添加滚轮缩放瞄准倍率功能,删除迫击炮GUI,优化迫击炮操作方式
This commit is contained in:
parent
58a12c2cf9
commit
22a54742d6
16 changed files with 174 additions and 271 deletions
|
@ -14,7 +14,7 @@ def getGitCommitHash() {
|
|||
return stdout.toString().trim()
|
||||
}
|
||||
|
||||
version = '0.1.3-SNAPSHOT-' + getGitCommitHash()
|
||||
version = '0.1.4-SNAPSHOT-' + getGitCommitHash()
|
||||
group = 'com.Atsushio.target'
|
||||
archivesBaseName = 'target'
|
||||
|
||||
|
|
|
@ -95,13 +95,14 @@ public class TargetMod {
|
|||
addNetworkMessage(DoubleJumpMessage.class, DoubleJumpMessage::buffer, DoubleJumpMessage::new, DoubleJumpMessage::handler);
|
||||
addNetworkMessage(GunsDataMessage.class, GunsDataMessage::encode, GunsDataMessage::decode, GunsDataMessage::handler, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
||||
addNetworkMessage(FireMessage.class, FireMessage::buffer, FireMessage::new, FireMessage::handler);
|
||||
addNetworkMessage(MortarGUIButtonMessage.class, MortarGUIButtonMessage::buffer, MortarGUIButtonMessage::new, MortarGUIButtonMessage::handler);
|
||||
addNetworkMessage(FireModeMessage.class, FireModeMessage::buffer, FireModeMessage::new, FireModeMessage::handler);
|
||||
addNetworkMessage(GunRecycleGuiButtonMessage.class, GunRecycleGuiButtonMessage::buffer, GunRecycleGuiButtonMessage::new, GunRecycleGuiButtonMessage::handler);
|
||||
addNetworkMessage(ReloadMessage.class, ReloadMessage::buffer, ReloadMessage::new, ReloadMessage::handler);
|
||||
addNetworkMessage(PlayerGunKillMessage.class, PlayerGunKillMessage::encode, PlayerGunKillMessage::decode, PlayerGunKillMessage::handler, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
||||
addNetworkMessage(ClientIndicatorMessage.class, ClientIndicatorMessage::encode, ClientIndicatorMessage::decode, ClientIndicatorMessage::handler, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
||||
addNetworkMessage(SensitivityMessage.class, SensitivityMessage::encode, SensitivityMessage::decode, SensitivityMessage::handler);
|
||||
addNetworkMessage(AdjustZoomFovMessage.class, AdjustZoomFovMessage::encode, AdjustZoomFovMessage::decode, AdjustZoomFovMessage::handler);
|
||||
addNetworkMessage(AdjustMortarAngleMessage.class, AdjustMortarAngleMessage::encode, AdjustMortarAngleMessage::decode, AdjustMortarAngleMessage::handler);
|
||||
|
||||
event.enqueueWork(() -> BrewingRecipeRegistry.addRecipe(Ingredient.of(PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER)),
|
||||
Ingredient.of(Items.LIGHTNING_ROD), PotionUtils.setPotion(new ItemStack(Items.POTION), TargetModPotion.SHOCK.get())));
|
||||
|
|
|
@ -2,18 +2,22 @@ package net.mcreator.target.client;
|
|||
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import net.mcreator.target.TargetMod;
|
||||
import net.mcreator.target.entity.MortarEntity;
|
||||
import net.mcreator.target.entity.Target1Entity;
|
||||
import net.mcreator.target.entity.TargetEntity;
|
||||
import net.mcreator.target.init.TargetModKeyMappings;
|
||||
import net.mcreator.target.init.TargetModMobEffects;
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.mcreator.target.item.gun.GunItem;
|
||||
import net.mcreator.target.network.TargetModVariables;
|
||||
import net.mcreator.target.network.message.FireMessage;
|
||||
import net.mcreator.target.network.message.SensitivityMessage;
|
||||
import net.mcreator.target.network.message.ZoomMessage;
|
||||
import net.mcreator.target.network.message.*;
|
||||
import net.mcreator.target.tools.TraceTool;
|
||||
import net.minecraft.client.KeyMapping;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
@ -106,11 +110,29 @@ public class ClickHandler {
|
|||
|
||||
@SubscribeEvent
|
||||
public static void onMouseScrolling(InputEvent.MouseScrollingEvent event) {
|
||||
if (notInGame()) return;
|
||||
|
||||
Player player = Minecraft.getInstance().player;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
var tag = stack.getOrCreateTag();
|
||||
double scroll = event.getScrollDelta();
|
||||
|
||||
if (notInGame()) return;
|
||||
if (player == null) return;
|
||||
|
||||
if (stack.is(TargetModTags.Items.GUN) && (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).zoom) {
|
||||
if (tag.getDouble("min_zoom") != 0 && tag.getDouble("max_zoom") != 0) {
|
||||
TargetMod.PACKET_HANDLER.sendToServer(new AdjustZoomFovMessage(scroll));
|
||||
}
|
||||
event.setCanceled(true);
|
||||
}
|
||||
|
||||
Entity looking = TraceTool.findLookingEntity(player, 6);
|
||||
if (looking == null) return;
|
||||
if (looking instanceof MortarEntity && player.isShiftKeyDown()){
|
||||
TargetMod.PACKET_HANDLER.sendToServer(new AdjustMortarAngleMessage(scroll));
|
||||
event.setCanceled(true);
|
||||
}
|
||||
|
||||
|
||||
if (Minecraft.getInstance().player.hasEffect(TargetModMobEffects.SHOCK.get())) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
|
|
|
@ -1,137 +0,0 @@
|
|||
package net.mcreator.target.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.mcreator.target.TargetMod;
|
||||
import net.mcreator.target.network.message.MortarGUIButtonMessage;
|
||||
import net.mcreator.target.tools.TraceTool;
|
||||
import net.mcreator.target.world.inventory.MortarGUIMenu;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class MortarGUIScreen extends AbstractContainerScreen<MortarGUIMenu> {
|
||||
private final static HashMap<String, Object> GUI_STATE = MortarGUIMenu.GUI_STATE;
|
||||
private final int x, y, z;
|
||||
private final Player entity;
|
||||
Button button_angle_add_1;
|
||||
Button button_angle_reduce_1;
|
||||
Button button_angle_add_10;
|
||||
Button button_angle_reduce_10;
|
||||
Button button_angle_reduce_05;
|
||||
Button button_angle_add_05;
|
||||
|
||||
public MortarGUIScreen(MortarGUIMenu container, Inventory inventory, Component text) {
|
||||
super(container, inventory, text);
|
||||
this.x = container.x;
|
||||
this.y = container.y;
|
||||
this.z = container.z;
|
||||
this.entity = container.entity;
|
||||
this.imageWidth = 0;
|
||||
this.imageHeight = 166;
|
||||
}
|
||||
|
||||
private static final ResourceLocation texture = new ResourceLocation("target:textures/screens/mortar_gui.png");
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
|
||||
this.renderBackground(guiGraphics);
|
||||
super.render(guiGraphics, mouseX, mouseY, partialTicks);
|
||||
this.renderTooltip(guiGraphics, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderBg(GuiGraphics guiGraphics, float partialTicks, int gx, int gy) {
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
guiGraphics.blit(texture, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight, this.imageWidth, this.imageHeight);
|
||||
RenderSystem.disableBlend();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int key, int b, int c) {
|
||||
if (key == 256) {
|
||||
if (this.minecraft != null && this.minecraft.player != null) {
|
||||
this.minecraft.player.closeContainer();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return super.keyPressed(key, b, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void containerTick() {
|
||||
super.containerTick();
|
||||
}
|
||||
|
||||
private String getAngleString(Entity entity) {
|
||||
if (entity == null) return "";
|
||||
Entity mortar = TraceTool.findLookingEntity(entity, 6);
|
||||
if (mortar == null) return "";
|
||||
return "Angle: " + new DecimalFormat("##.#").format(-mortar.getXRot());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) {
|
||||
guiGraphics.drawString(this.font, getAngleString(entity), -18, 98, -1, false);
|
||||
|
||||
Entity looking = TraceTool.findLookingEntity(entity, 6);
|
||||
var range = looking == null ? 0 : -looking.getXRot();
|
||||
|
||||
guiGraphics.drawString(this.font, Component.literal("Range:" + (int) RangeHelper.getRange(range)), -18, 108, -16711885, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
button_angle_add_1 = Button.builder(Component.translatable("gui.target.mortar_gui.button_angle_add_1"), e -> {
|
||||
TargetMod.PACKET_HANDLER.sendToServer(new MortarGUIButtonMessage(0, x, y, z));
|
||||
MortarGUIButtonMessage.handleButtonAction(entity, 0);
|
||||
}).bounds(this.leftPos + 42, this.topPos + 124, 29, 20).build();
|
||||
GUI_STATE.put("button:button_angle_add_1", button_angle_add_1);
|
||||
this.addRenderableWidget(button_angle_add_1);
|
||||
button_angle_reduce_1 = Button.builder(Component.translatable("gui.target.mortar_gui.button_angle_reduce_1"), e -> {
|
||||
TargetMod.PACKET_HANDLER.sendToServer(new MortarGUIButtonMessage(1, x, y, z));
|
||||
MortarGUIButtonMessage.handleButtonAction(entity, 1);
|
||||
}).bounds(this.leftPos - 73, this.topPos + 124, 30, 20).build();
|
||||
GUI_STATE.put("button:button_angle_reduce_1", button_angle_reduce_1);
|
||||
this.addRenderableWidget(button_angle_reduce_1);
|
||||
button_angle_add_10 = Button.builder(Component.translatable("gui.target.mortar_gui.button_angle_add_10"), e -> {
|
||||
TargetMod.PACKET_HANDLER.sendToServer(new MortarGUIButtonMessage(2, x, y, z));
|
||||
MortarGUIButtonMessage.handleButtonAction(entity, 2);
|
||||
}).bounds(this.leftPos + 43, this.topPos + 151, 28, 20).build();
|
||||
GUI_STATE.put("button:button_angle_add_10", button_angle_add_10);
|
||||
this.addRenderableWidget(button_angle_add_10);
|
||||
button_angle_reduce_10 = Button.builder(Component.translatable("gui.target.mortar_gui.button_angle_reduce_10"), e -> {
|
||||
TargetMod.PACKET_HANDLER.sendToServer(new MortarGUIButtonMessage(3, x, y, z));
|
||||
MortarGUIButtonMessage.handleButtonAction(entity, 3);
|
||||
}).bounds(this.leftPos - 73, this.topPos + 151, 30, 20).build();
|
||||
GUI_STATE.put("button:button_angle_reduce_10", button_angle_reduce_10);
|
||||
this.addRenderableWidget(button_angle_reduce_10);
|
||||
button_angle_reduce_05 = Button.builder(Component.translatable("gui.target.mortar_gui.button_angle_reduce_05"), e -> {
|
||||
TargetMod.PACKET_HANDLER.sendToServer(new MortarGUIButtonMessage(4, x, y, z));
|
||||
MortarGUIButtonMessage.handleButtonAction(entity, 4);
|
||||
}).bounds(this.leftPos - 73, this.topPos + 97, 30, 20).build();
|
||||
GUI_STATE.put("button:button_angle_reduce_05", button_angle_reduce_05);
|
||||
this.addRenderableWidget(button_angle_reduce_05);
|
||||
button_angle_add_05 = Button.builder(Component.translatable("gui.target.mortar_gui.button_angle_add_05"), e -> {
|
||||
TargetMod.PACKET_HANDLER.sendToServer(new MortarGUIButtonMessage(5, x, y, z));
|
||||
MortarGUIButtonMessage.handleButtonAction(entity, 5);
|
||||
}).bounds(this.leftPos + 42, this.topPos + 97, 29, 20).build();
|
||||
GUI_STATE.put("button:button_angle_add_05", button_angle_add_05);
|
||||
this.addRenderableWidget(button_angle_add_05);
|
||||
}
|
||||
}
|
|
@ -159,12 +159,8 @@ public class MortarEntity extends PathfinderMob implements GeoEntity, AnimatedEn
|
|||
@Override
|
||||
public InteractionResult mobInteract(Player player, InteractionHand hand) {
|
||||
super.mobInteract(player, hand);
|
||||
double x = this.getX();
|
||||
double y = this.getY();
|
||||
double z = this.getZ();
|
||||
|
||||
ItemStack mainHandItem = player.getMainHandItem();
|
||||
if (mainHandItem.getItem() == ItemStack.EMPTY.getItem()) {
|
||||
if (player.isShiftKeyDown()) {
|
||||
this.setYRot(player.getYRot());
|
||||
this.setXRot(this.getXRot());
|
||||
|
@ -174,21 +170,8 @@ public class MortarEntity extends PathfinderMob implements GeoEntity, AnimatedEn
|
|||
this.xRotO = this.getXRot();
|
||||
this.yBodyRotO = this.getYRot();
|
||||
this.yHeadRotO = this.getYRot();
|
||||
} else if (player instanceof ServerPlayer serverPlayer) {
|
||||
NetworkHooks.openScreen(serverPlayer, new MenuProvider() {
|
||||
@Override
|
||||
public Component getDisplayName() {
|
||||
return Component.literal("MortarGUI");
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractContainerMenu createMenu(int id, Inventory inventory, Player player) {
|
||||
return new MortarGUIMenu(id, inventory, new FriendlyByteBuf(Unpooled.buffer()).writeBlockPos(BlockPos.containing(x, y, z)));
|
||||
}
|
||||
}, BlockPos.containing(x, y, z));
|
||||
}
|
||||
}
|
||||
if (mainHandItem.getItem() == TargetModItems.MORTAR_SHELLS.get() && !player.getCooldowns().isOnCooldown(TargetModItems.MORTAR_SHELLS.get())) {
|
||||
if (mainHandItem.getItem() == TargetModItems.MORTAR_SHELLS.get() && !player.getCooldowns().isOnCooldown(TargetModItems.MORTAR_SHELLS.get()) && !player.isShiftKeyDown()) {
|
||||
player.getCooldowns().addCooldown(TargetModItems.MORTAR_SHELLS.get(), 30);
|
||||
if (!player.isCreative()) {
|
||||
player.getInventory().clearOrCountMatchingItems(p -> TargetModItems.MORTAR_SHELLS.get() == p.getItem(), 1, player.inventoryMenu.getCraftSlots());
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.mcreator.target.event;
|
||||
|
||||
import net.mcreator.target.init.TargetModAttributes;
|
||||
import net.mcreator.target.init.TargetModItems;
|
||||
import net.mcreator.target.init.TargetModMobEffects;
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.mcreator.target.network.TargetModVariables;
|
||||
|
@ -385,7 +386,8 @@ public class ClientEventHandler {
|
|||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
double p = player.getPersistentData().getDouble("zoom_pos");
|
||||
double zoom = stack.getOrCreateTag().getDouble("zoom");
|
||||
|
||||
double zoom = stack.getOrCreateTag().getDouble("zoom") + stack.getOrCreateTag().getDouble("custom_zoom");
|
||||
|
||||
if (stack.is(TargetModTags.Items.GUN)) {
|
||||
event.setFOV(event.getFOV() / (1.0 + p * (zoom - 1)));
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package net.mcreator.target.init;
|
||||
|
||||
import net.mcreator.target.client.gui.GunRecycleGuiScreen;
|
||||
import net.mcreator.target.client.gui.MortarGUIScreen;
|
||||
import net.minecraft.client.gui.screens.MenuScreens;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
@ -13,7 +12,6 @@ public class TargetModScreens {
|
|||
@SubscribeEvent
|
||||
public static void clientLoad(FMLClientSetupEvent event) {
|
||||
event.enqueueWork(() -> {
|
||||
MenuScreens.register(TargetModMenus.MORTAR_GUI.get(), MortarGUIScreen::new);
|
||||
MenuScreens.register(TargetModMenus.GUN_RECYCLE_GUI.get(), GunRecycleGuiScreen::new);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -181,5 +181,6 @@ public class TargetModSounds {
|
|||
public static final RegistryObject<SoundEvent> M_870_VERYFAR = REGISTRY.register("m_870_veryfar", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "m_870_veryfar")));
|
||||
public static final RegistryObject<SoundEvent> M_870_PREPARE_ALT = REGISTRY.register("m_870_preparealt", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "m_870_preparealt")));
|
||||
public static final RegistryObject<SoundEvent> M_870_RELOAD_LOOP = REGISTRY.register("m_870_reloadloop", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "m_870_reloadloop")));
|
||||
public static final RegistryObject<SoundEvent> BULLET_SUPPLY = REGISTRY.register("bulletsupply", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "bulletsupply")));
|
||||
public static final RegistryObject<SoundEvent> BULLET_SUPPLY = REGISTRY.register("bullet_supply", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "bullet_supply")));
|
||||
public static final RegistryObject<SoundEvent> ADJUST_FOV = REGISTRY.register("adjust_fov", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation("target", "adjust_fov")));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
package net.mcreator.target.network.message;
|
||||
|
||||
import net.mcreator.target.client.gui.RangeHelper;
|
||||
import net.mcreator.target.entity.MortarEntity;
|
||||
import net.mcreator.target.init.TargetModAttributes;
|
||||
import net.mcreator.target.init.TargetModSounds;
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.mcreator.target.tools.SoundTool;
|
||||
import net.mcreator.target.tools.TraceTool;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class AdjustMortarAngleMessage {
|
||||
private final double scroll;
|
||||
|
||||
public AdjustMortarAngleMessage(double scroll) {
|
||||
this.scroll = scroll;
|
||||
}
|
||||
|
||||
public static void encode(AdjustMortarAngleMessage message, FriendlyByteBuf byteBuf) {
|
||||
byteBuf.writeDouble(message.scroll);
|
||||
}
|
||||
|
||||
public static AdjustMortarAngleMessage decode(FriendlyByteBuf byteBuf) {
|
||||
return new AdjustMortarAngleMessage(byteBuf.readDouble());
|
||||
}
|
||||
|
||||
public static void handler(AdjustMortarAngleMessage message, Supplier<NetworkEvent.Context> context) {
|
||||
context.get().enqueueWork(() -> {
|
||||
ServerPlayer player = context.get().getSender();
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity looking = TraceTool.findLookingEntity(player, 6);
|
||||
if (looking == null) return;
|
||||
|
||||
double angle = 0;
|
||||
|
||||
if (looking instanceof LivingEntity living){
|
||||
living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).setBaseValue(Mth.clamp(living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() + message.scroll,20,89));
|
||||
angle = living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue();
|
||||
}
|
||||
|
||||
var range = -looking.getXRot();
|
||||
|
||||
player.displayClientMessage(Component.literal("Angle:" + new java.text.DecimalFormat("##.#").format(angle) + " Range:" + new java.text.DecimalFormat("##.#").format((int) RangeHelper.getRange(range)) + "M"), true);
|
||||
SoundTool.playLocalSound(player, TargetModSounds.ADJUST_FOV.get(), 1f, 0.7f);
|
||||
});
|
||||
context.get().setPacketHandled(true);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package net.mcreator.target.network.message;
|
||||
|
||||
import net.mcreator.target.init.TargetModSounds;
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.mcreator.target.tools.SoundTool;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class AdjustZoomFovMessage {
|
||||
private final double scroll;
|
||||
|
||||
public AdjustZoomFovMessage(double scroll) {
|
||||
this.scroll = scroll;
|
||||
}
|
||||
|
||||
public static void encode(AdjustZoomFovMessage message, FriendlyByteBuf byteBuf) {
|
||||
byteBuf.writeDouble(message.scroll);
|
||||
}
|
||||
|
||||
public static AdjustZoomFovMessage decode(FriendlyByteBuf byteBuf) {
|
||||
return new AdjustZoomFovMessage(byteBuf.readDouble());
|
||||
}
|
||||
|
||||
public static void handler(AdjustZoomFovMessage message, Supplier<NetworkEvent.Context> context) {
|
||||
context.get().enqueueWork(() -> {
|
||||
ServerPlayer player = context.get().getSender();
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
var tag = stack.getOrCreateTag();
|
||||
if (!stack.is(TargetModTags.Items.GUN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double min_zoom = tag.getDouble("min_zoom") - tag.getDouble("zoom");
|
||||
double max_zoom = tag.getDouble("max_zoom") - tag.getDouble("zoom");
|
||||
tag.putDouble("custom_zoom", Mth.clamp(tag.getDouble("custom_zoom") + 0.5 * message.scroll, min_zoom,max_zoom));
|
||||
if (tag.getDouble("custom_zoom") > min_zoom && tag.getDouble("custom_zoom") < max_zoom) {
|
||||
SoundTool.playLocalSound(player, TargetModSounds.ADJUST_FOV.get(), 1f, 0.7f);
|
||||
}
|
||||
});
|
||||
context.get().setPacketHandled(true);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
package net.mcreator.target.network.message;
|
||||
|
||||
import net.mcreator.target.init.TargetModAttributes;
|
||||
import net.mcreator.target.tools.TraceTool;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class MortarGUIButtonMessage {
|
||||
private final int buttonID, x, y, z;
|
||||
|
||||
public MortarGUIButtonMessage(FriendlyByteBuf buffer) {
|
||||
this.buttonID = buffer.readInt();
|
||||
this.x = buffer.readInt();
|
||||
this.y = buffer.readInt();
|
||||
this.z = buffer.readInt();
|
||||
}
|
||||
|
||||
public MortarGUIButtonMessage(int buttonID, int x, int y, int z) {
|
||||
this.buttonID = buttonID;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public static void buffer(MortarGUIButtonMessage message, FriendlyByteBuf buffer) {
|
||||
buffer.writeInt(message.buttonID);
|
||||
buffer.writeInt(message.x);
|
||||
buffer.writeInt(message.y);
|
||||
buffer.writeInt(message.z);
|
||||
}
|
||||
|
||||
public static void handler(MortarGUIButtonMessage message, Supplier<NetworkEvent.Context> contextSupplier) {
|
||||
NetworkEvent.Context context = contextSupplier.get();
|
||||
context.enqueueWork(() -> {
|
||||
Player entity = context.getSender();
|
||||
|
||||
if (entity == null) return;
|
||||
|
||||
int buttonID = message.buttonID;
|
||||
int x = message.x;
|
||||
int y = message.y;
|
||||
int z = message.z;
|
||||
|
||||
if (!entity.level().isLoaded(new BlockPos(x, y, z))) return;
|
||||
|
||||
handleButtonAction(entity, buttonID);
|
||||
});
|
||||
context.setPacketHandled(true);
|
||||
}
|
||||
|
||||
public static void handleButtonAction(Player player, int buttonID) {
|
||||
Entity looking = TraceTool.findLookingEntity(player, 6);
|
||||
if (looking == null) return;
|
||||
if (looking instanceof LivingEntity living) {
|
||||
switch (buttonID) {
|
||||
case 0 -> {
|
||||
if (living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() < 89) {
|
||||
living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).setBaseValue((living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() + 1));
|
||||
}
|
||||
}
|
||||
case 1 -> {
|
||||
if (living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() > 21) {
|
||||
living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).setBaseValue((living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() - 1));
|
||||
}
|
||||
}
|
||||
case 2 -> {
|
||||
if (living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() < 78) {
|
||||
living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).setBaseValue((living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() + 10));
|
||||
}
|
||||
}
|
||||
case 3 -> {
|
||||
if (living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() > 31) {
|
||||
living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).setBaseValue((living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() - 10));
|
||||
}
|
||||
}
|
||||
case 4 -> {
|
||||
if (living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() > 20.5) {
|
||||
living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).setBaseValue((living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() - 0.5));
|
||||
}
|
||||
}
|
||||
case 5 -> {
|
||||
if (living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() < 88.5) {
|
||||
living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).setBaseValue((living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() + 0.5));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1514,5 +1514,13 @@
|
|||
"stream": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"adjust_fov": {
|
||||
"sounds": [
|
||||
{
|
||||
"name": "target:adjust_fov",
|
||||
"stream": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
BIN
src/main/resources/assets/target/sounds/adjust_fov.ogg
Normal file
BIN
src/main/resources/assets/target/sounds/adjust_fov.ogg
Normal file
Binary file not shown.
|
@ -1,6 +1,8 @@
|
|||
{
|
||||
"zoom_speed": 0.6,
|
||||
"zoom": 6,
|
||||
"min_zoom": 4,
|
||||
"max_zoom": 10,
|
||||
"bipod": 1,
|
||||
"dev": 6,
|
||||
"recoil_x": 0.008,
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
{
|
||||
"zoom_speed": 0.75,
|
||||
"zoom": 8,
|
||||
"zoom": 6,
|
||||
"min_zoom": 4,
|
||||
"max_zoom": 8,
|
||||
"dev": 6,
|
||||
"recoil_x": 0.007,
|
||||
"recoil_y": 0.013,
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
{
|
||||
"zoom_speed": 0.85,
|
||||
"zoom": 4,
|
||||
"min_zoom": 1.25,
|
||||
"max_zoom": 6,
|
||||
"dev": 6,
|
||||
"bipod": 1,
|
||||
"recoil_x": 0.006,
|
||||
|
|
Loading…
Add table
Reference in a new issue