优化代码

This commit is contained in:
17146 2024-05-16 15:17:50 +08:00
parent 4e01d34071
commit 75c206d68c
13 changed files with 77 additions and 100 deletions

View file

@ -1,10 +1,7 @@
package net.mcreator.target; package net.mcreator.target;
import net.mcreator.target.init.*; import net.mcreator.target.init.*;
import net.mcreator.target.network.DoubleJumpMessage; import net.mcreator.target.network.*;
import net.mcreator.target.network.FireMessage;
import net.mcreator.target.network.GunsDataMessage;
import net.mcreator.target.network.ZoomMessage;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
@ -87,5 +84,6 @@ public class TargetMod {
addNetworkMessage(DoubleJumpMessage.class, DoubleJumpMessage::buffer, DoubleJumpMessage::new, DoubleJumpMessage::handler); 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(GunsDataMessage.class, GunsDataMessage::encode, GunsDataMessage::decode, GunsDataMessage::handler, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
addNetworkMessage(FireMessage.class, FireMessage::buffer, FireMessage::new, FireMessage::handler); addNetworkMessage(FireMessage.class, FireMessage::buffer, FireMessage::new, FireMessage::handler);
addNetworkMessage(MortarGUIButtonMessage.class, MortarGUIButtonMessage::buffer, MortarGUIButtonMessage::new, MortarGUIButtonMessage::handler);
} }
} }

View file

@ -11,20 +11,17 @@ import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import java.util.HashMap; import java.util.HashMap;
public class GunRecycleGuiScreen extends AbstractContainerScreen<GunRecycleGuiMenu> { public class GunRecycleGuiScreen extends AbstractContainerScreen<GunRecycleGuiMenu> {
private final static HashMap<String, Object> guistate = GunRecycleGuiMenu.guistate; private final static HashMap<String, Object> GUI_STATE = GunRecycleGuiMenu.GUI_STATE;
private final Level world;
private final int x, y, z; private final int x, y, z;
private final Player entity; private final Player entity;
Button button_dismantle; Button button_dismantle;
public GunRecycleGuiScreen(GunRecycleGuiMenu container, Inventory inventory, Component text) { public GunRecycleGuiScreen(GunRecycleGuiMenu container, Inventory inventory, Component text) {
super(container, inventory, text); super(container, inventory, text);
this.world = container.world;
this.x = container.x; this.x = container.x;
this.y = container.y; this.y = container.y;
this.z = container.z; this.z = container.z;
@ -56,7 +53,9 @@ public class GunRecycleGuiScreen extends AbstractContainerScreen<GunRecycleGuiMe
@Override @Override
public boolean keyPressed(int key, int b, int c) { public boolean keyPressed(int key, int b, int c) {
if (key == 256) { if (key == 256) {
this.minecraft.player.closeContainer(); if (this.minecraft != null && this.minecraft.player != null) {
this.minecraft.player.closeContainer();
}
return true; return true;
} }
return super.keyPressed(key, b, c); return super.keyPressed(key, b, c);
@ -84,7 +83,7 @@ public class GunRecycleGuiScreen extends AbstractContainerScreen<GunRecycleGuiMe
TargetMod.PACKET_HANDLER.sendToServer(new GunRecycleGuiButtonMessage(0, x, y, z)); TargetMod.PACKET_HANDLER.sendToServer(new GunRecycleGuiButtonMessage(0, x, y, z));
GunRecycleGuiButtonMessage.handleButtonAction(entity, 0, x, y, z); GunRecycleGuiButtonMessage.handleButtonAction(entity, 0, x, y, z);
}).bounds(this.leftPos + 62, this.topPos + 56, 52, 20).build(); }).bounds(this.leftPos + 62, this.topPos + 56, 52, 20).build();
guistate.put("button:button_dismantle", button_dismantle); GUI_STATE.put("button:button_dismantle", button_dismantle);
this.addRenderableWidget(button_dismantle); this.addRenderableWidget(button_dismantle);
} }
} }

View file

@ -13,14 +13,12 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.HashMap; import java.util.HashMap;
public class MortarGUIScreen extends AbstractContainerScreen<MortarGUIMenu> { public class MortarGUIScreen extends AbstractContainerScreen<MortarGUIMenu> {
private final static HashMap<String, Object> guistate = MortarGUIMenu.guistate; private final static HashMap<String, Object> GUI_STATE = MortarGUIMenu.GUI_STATE;
private final Level world;
private final int x, y, z; private final int x, y, z;
private final Player entity; private final Player entity;
Button button_zeng_da_yang_jiao; Button button_zeng_da_yang_jiao;
@ -32,7 +30,6 @@ public class MortarGUIScreen extends AbstractContainerScreen<MortarGUIMenu> {
public MortarGUIScreen(MortarGUIMenu container, Inventory inventory, Component text) { public MortarGUIScreen(MortarGUIMenu container, Inventory inventory, Component text) {
super(container, inventory, text); super(container, inventory, text);
this.world = container.world;
this.x = container.x; this.x = container.x;
this.y = container.y; this.y = container.y;
this.z = container.z; this.z = container.z;
@ -62,7 +59,9 @@ public class MortarGUIScreen extends AbstractContainerScreen<MortarGUIMenu> {
@Override @Override
public boolean keyPressed(int key, int b, int c) { public boolean keyPressed(int key, int b, int c) {
if (key == 256) { if (key == 256) {
this.minecraft.player.closeContainer(); if (this.minecraft != null && this.minecraft.player != null) {
this.minecraft.player.closeContainer();
}
return true; return true;
} }
return super.keyPressed(key, b, c); return super.keyPressed(key, b, c);
@ -102,37 +101,37 @@ public class MortarGUIScreen extends AbstractContainerScreen<MortarGUIMenu> {
TargetMod.PACKET_HANDLER.sendToServer(new MortarGUIButtonMessage(0, x, y, z)); TargetMod.PACKET_HANDLER.sendToServer(new MortarGUIButtonMessage(0, x, y, z));
MortarGUIButtonMessage.handleButtonAction(entity, 0, x, y, z); MortarGUIButtonMessage.handleButtonAction(entity, 0, x, y, z);
}).bounds(this.leftPos + 42, this.topPos + 124, 29, 20).build(); }).bounds(this.leftPos + 42, this.topPos + 124, 29, 20).build();
guistate.put("button:button_zeng_da_yang_jiao", button_zeng_da_yang_jiao); GUI_STATE.put("button:button_zeng_da_yang_jiao", button_zeng_da_yang_jiao);
this.addRenderableWidget(button_zeng_da_yang_jiao); this.addRenderableWidget(button_zeng_da_yang_jiao);
button_empty = Button.builder(Component.translatable("gui.target.mortar_gui.button_empty"), e -> { button_empty = Button.builder(Component.translatable("gui.target.mortar_gui.button_empty"), e -> {
TargetMod.PACKET_HANDLER.sendToServer(new MortarGUIButtonMessage(1, x, y, z)); TargetMod.PACKET_HANDLER.sendToServer(new MortarGUIButtonMessage(1, x, y, z));
MortarGUIButtonMessage.handleButtonAction(entity, 1, x, y, z); MortarGUIButtonMessage.handleButtonAction(entity, 1, x, y, z);
}).bounds(this.leftPos - 73, this.topPos + 124, 30, 20).build(); }).bounds(this.leftPos - 73, this.topPos + 124, 30, 20).build();
guistate.put("button:button_empty", button_empty); GUI_STATE.put("button:button_empty", button_empty);
this.addRenderableWidget(button_empty); this.addRenderableWidget(button_empty);
button_10 = Button.builder(Component.translatable("gui.target.mortar_gui.button_10"), e -> { button_10 = Button.builder(Component.translatable("gui.target.mortar_gui.button_10"), e -> {
TargetMod.PACKET_HANDLER.sendToServer(new MortarGUIButtonMessage(2, x, y, z)); TargetMod.PACKET_HANDLER.sendToServer(new MortarGUIButtonMessage(2, x, y, z));
MortarGUIButtonMessage.handleButtonAction(entity, 2, x, y, z); MortarGUIButtonMessage.handleButtonAction(entity, 2, x, y, z);
}).bounds(this.leftPos + 43, this.topPos + 151, 28, 20).build(); }).bounds(this.leftPos + 43, this.topPos + 151, 28, 20).build();
guistate.put("button:button_10", button_10); GUI_STATE.put("button:button_10", button_10);
this.addRenderableWidget(button_10); this.addRenderableWidget(button_10);
button_101 = Button.builder(Component.translatable("gui.target.mortar_gui.button_101"), e -> { button_101 = Button.builder(Component.translatable("gui.target.mortar_gui.button_101"), e -> {
TargetMod.PACKET_HANDLER.sendToServer(new MortarGUIButtonMessage(3, x, y, z)); TargetMod.PACKET_HANDLER.sendToServer(new MortarGUIButtonMessage(3, x, y, z));
MortarGUIButtonMessage.handleButtonAction(entity, 3, x, y, z); MortarGUIButtonMessage.handleButtonAction(entity, 3, x, y, z);
}).bounds(this.leftPos - 73, this.topPos + 151, 30, 20).build(); }).bounds(this.leftPos - 73, this.topPos + 151, 30, 20).build();
guistate.put("button:button_101", button_101); GUI_STATE.put("button:button_101", button_101);
this.addRenderableWidget(button_101); this.addRenderableWidget(button_101);
button_05 = Button.builder(Component.translatable("gui.target.mortar_gui.button_05"), e -> { button_05 = Button.builder(Component.translatable("gui.target.mortar_gui.button_05"), e -> {
TargetMod.PACKET_HANDLER.sendToServer(new MortarGUIButtonMessage(4, x, y, z)); TargetMod.PACKET_HANDLER.sendToServer(new MortarGUIButtonMessage(4, x, y, z));
MortarGUIButtonMessage.handleButtonAction(entity, 4, x, y, z); MortarGUIButtonMessage.handleButtonAction(entity, 4, x, y, z);
}).bounds(this.leftPos - 73, this.topPos + 97, 30, 20).build(); }).bounds(this.leftPos - 73, this.topPos + 97, 30, 20).build();
guistate.put("button:button_05", button_05); GUI_STATE.put("button:button_05", button_05);
this.addRenderableWidget(button_05); this.addRenderableWidget(button_05);
button_051 = Button.builder(Component.translatable("gui.target.mortar_gui.button_051"), e -> { button_051 = Button.builder(Component.translatable("gui.target.mortar_gui.button_051"), e -> {
TargetMod.PACKET_HANDLER.sendToServer(new MortarGUIButtonMessage(5, x, y, z)); TargetMod.PACKET_HANDLER.sendToServer(new MortarGUIButtonMessage(5, x, y, z));
MortarGUIButtonMessage.handleButtonAction(entity, 5, x, y, z); MortarGUIButtonMessage.handleButtonAction(entity, 5, x, y, z);
}).bounds(this.leftPos + 42, this.topPos + 97, 29, 20).build(); }).bounds(this.leftPos + 42, this.topPos + 97, 29, 20).build();
guistate.put("button:button_051", button_051); GUI_STATE.put("button:button_051", button_051);
this.addRenderableWidget(button_051); this.addRenderableWidget(button_051);
} }
} }

View file

@ -7,7 +7,7 @@ import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public class BulltholeParticle extends TextureSheetParticle { public class BulletHoleParticle extends TextureSheetParticle {
public static BulltholeParticleProvider provider(SpriteSet spriteSet) { public static BulltholeParticleProvider provider(SpriteSet spriteSet) {
return new BulltholeParticleProvider(spriteSet); return new BulltholeParticleProvider(spriteSet);
} }
@ -20,15 +20,12 @@ public class BulltholeParticle extends TextureSheetParticle {
} }
public Particle createParticle(SimpleParticleType typeIn, ClientLevel worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) { public Particle createParticle(SimpleParticleType typeIn, ClientLevel worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
return new BulltholeParticle(worldIn, x, y, z, xSpeed, ySpeed, zSpeed, this.spriteSet); return new BulletHoleParticle(worldIn, x, y, z, xSpeed, ySpeed, zSpeed, this.spriteSet);
} }
} }
private final SpriteSet spriteSet; protected BulletHoleParticle(ClientLevel world, double x, double y, double z, double vx, double vy, double vz, SpriteSet spriteSet) {
protected BulltholeParticle(ClientLevel world, double x, double y, double z, double vx, double vy, double vz, SpriteSet spriteSet) {
super(world, x, y, z); super(world, x, y, z);
this.spriteSet = spriteSet;
this.setSize(0f, 0f); this.setSize(0f, 0f);
this.lifetime = 100; this.lifetime = 100;
this.gravity = 0f; this.gravity = 0f;

View file

@ -7,7 +7,7 @@ import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public class FirestarParticle extends TextureSheetParticle { public class FireStarParticle extends TextureSheetParticle {
public static FirestarParticleProvider provider(SpriteSet spriteSet) { public static FirestarParticleProvider provider(SpriteSet spriteSet) {
return new FirestarParticleProvider(spriteSet); return new FirestarParticleProvider(spriteSet);
} }
@ -20,14 +20,13 @@ public class FirestarParticle extends TextureSheetParticle {
} }
public Particle createParticle(SimpleParticleType typeIn, ClientLevel worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) { public Particle createParticle(SimpleParticleType typeIn, ClientLevel worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
FirestarParticle particle = new FirestarParticle(worldIn, x, y, z, xSpeed, ySpeed, zSpeed, this.spriteSet); return new FireStarParticle(worldIn, x, y, z, xSpeed, ySpeed, zSpeed, this.spriteSet);
return particle;
} }
} }
private final SpriteSet spriteSet; private final SpriteSet spriteSet;
protected FirestarParticle(ClientLevel world, double x, double y, double z, double vx, double vy, double vz, SpriteSet spriteSet) { protected FireStarParticle(ClientLevel world, double x, double y, double z, double vx, double vy, double vz, SpriteSet spriteSet) {
super(world, x, y, z); super(world, x, y, z);
this.spriteSet = spriteSet; this.spriteSet = spriteSet;
this.setSize(0.2f, 0.2f); this.setSize(0.2f, 0.2f);

View file

@ -21,7 +21,7 @@ import net.minecraftforge.fml.common.Mod;
import org.joml.Matrix4f; import org.joml.Matrix4f;
@Mod.EventBusSubscriber({Dist.CLIENT}) @Mod.EventBusSubscriber({Dist.CLIENT})
public class CrosshairOverlay { public class CrossHairOverlay {
@SubscribeEvent(priority = EventPriority.NORMAL) @SubscribeEvent(priority = EventPriority.NORMAL)
public static void eventHandler(RenderGuiEvent.Pre event) { public static void eventHandler(RenderGuiEvent.Pre event) {
int w = event.getWindow().getGuiScaledWidth(); int w = event.getWindow().getGuiScaledWidth();

View file

@ -28,8 +28,8 @@ public class M79uiOverlay {
RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
RenderSystem.setShaderColor(1, 1, 1, 1); RenderSystem.setShaderColor(1, 1, 1, 1);
if (shouldRenderCrosshair(player)) { if (shouldRenderCrossHair(player)) {
event.getGuiGraphics().blit(new ResourceLocation("target:textures/screens/rex.png"), w / 2 + -16, h / 2 + -16, 0, 0, 32, 32, 32, 32); event.getGuiGraphics().blit(new ResourceLocation("target:textures/screens/rex.png"), w / 2 - 16, h / 2 - 16, 0, 0, 32, 32, 32, 32);
} }
RenderSystem.depthMask(true); RenderSystem.depthMask(true);
RenderSystem.defaultBlendFunc(); RenderSystem.defaultBlendFunc();
@ -38,7 +38,7 @@ public class M79uiOverlay {
RenderSystem.setShaderColor(1, 1, 1, 1); RenderSystem.setShaderColor(1, 1, 1, 1);
} }
private static boolean shouldRenderCrosshair(Player player) { private static boolean shouldRenderCrossHair(Player player) {
if (player == null) return false; if (player == null) return false;
return !player.isSpectator() return !player.isSpectator()
&& player.getMainHandItem().getItem() == TargetModItems.M_79.get() && player.getMainHandItem().getItem() == TargetModItems.M_79.get()

View file

@ -53,7 +53,6 @@ import software.bernie.geckolib.core.object.PlayState;
import software.bernie.geckolib.util.GeckoLibUtil; import software.bernie.geckolib.util.GeckoLibUtil;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.text.DecimalFormat;
public class MortarEntity extends PathfinderMob implements GeoEntity, AnimatedEntity { public class MortarEntity extends PathfinderMob implements GeoEntity, AnimatedEntity {
public static final EntityDataAccessor<Boolean> SHOOT = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.BOOLEAN); public static final EntityDataAccessor<Boolean> SHOOT = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.BOOLEAN);
@ -104,7 +103,7 @@ public class MortarEntity extends PathfinderMob implements GeoEntity, AnimatedEn
@Override @Override
public MobType getMobType() { public MobType getMobType() {
return MobType.UNDEFINED; return super.getMobType();
} }
@Override @Override

View file

@ -22,9 +22,7 @@ public class TargetModAttributes {
@SubscribeEvent @SubscribeEvent
public static void register(FMLConstructModEvent event) { public static void register(FMLConstructModEvent event) {
event.enqueueWork(() -> { event.enqueueWork(() -> ATTRIBUTES.register(FMLJavaModLoadingContext.get().getModEventBus()));
ATTRIBUTES.register(FMLJavaModLoadingContext.get().getModEventBus());
});
} }
@SubscribeEvent @SubscribeEvent

View file

@ -1,7 +1,7 @@
package net.mcreator.target.init; package net.mcreator.target.init;
import net.mcreator.target.client.particle.BulltholeParticle; import net.mcreator.target.client.particle.BulletHoleParticle;
import net.mcreator.target.client.particle.FirestarParticle; import net.mcreator.target.client.particle.FireStarParticle;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RegisterParticleProvidersEvent; import net.minecraftforge.client.event.RegisterParticleProvidersEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -11,8 +11,8 @@ import net.minecraftforge.fml.common.Mod;
public class TargetModParticles { public class TargetModParticles {
@SubscribeEvent @SubscribeEvent
public static void registerParticles(RegisterParticleProvidersEvent event) { public static void registerParticles(RegisterParticleProvidersEvent event) {
event.registerSpriteSet(TargetModParticleTypes.FIRESTAR.get(), FirestarParticle::provider); event.registerSpriteSet(TargetModParticleTypes.FIRESTAR.get(), FireStarParticle::provider);
event.registerSpriteSet(TargetModParticleTypes.BULLTHOLE.get(), BulltholeParticle::provider); event.registerSpriteSet(TargetModParticleTypes.BULLTHOLE.get(), BulletHoleParticle::provider);
} }
} }

View file

@ -1,24 +1,17 @@
package net.mcreator.target.network; package net.mcreator.target.network;
import net.mcreator.target.TargetMod; import net.mcreator.target.init.TargetModAttributes;
import net.mcreator.target.tools.TraceTool; import net.mcreator.target.tools.TraceTool;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.network.NetworkEvent; import net.minecraftforge.network.NetworkEvent;
import net.minecraft.world.entity.LivingEntity;
import net.mcreator.target.init.TargetModAttributes;
import java.util.function.Supplier; import java.util.function.Supplier;
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class MortarGUIButtonMessage { public class MortarGUIButtonMessage {
private final int buttonID, x, y, z; private final int buttonID, x, y, z;
@ -68,43 +61,39 @@ public class MortarGUIButtonMessage {
private static void handleButtonAction(Player player, int buttonID) { private static void handleButtonAction(Player player, int buttonID) {
Entity looking = TraceTool.findLookingEntity(player, 6); Entity looking = TraceTool.findLookingEntity(player, 6);
if (looking == null) return; if (looking == null) return;
if (looking instanceof LivingEntity living) {
switch (buttonID) { switch (buttonID) {
case 0 -> { case 0 -> {
if (((LivingEntity) looking).getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() < 89) { if (living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() < 89) {
((LivingEntity) looking).getAttribute(TargetModAttributes.MORTAR_PITCH.get()).setBaseValue((((LivingEntity) looking).getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() + 1)); living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).setBaseValue((living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() + 1));
}
} }
} case 1 -> {
case 1 -> { if (living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() > 21) {
if (((LivingEntity) looking).getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() > 21) { living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).setBaseValue((living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() - 1));
((LivingEntity) looking).getAttribute(TargetModAttributes.MORTAR_PITCH.get()).setBaseValue((((LivingEntity) looking).getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() - 1)); }
} }
} case 2 -> {
case 2 -> { if (living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() < 78) {
if (((LivingEntity) looking).getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() < 78) { living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).setBaseValue((living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() + 10));
((LivingEntity) looking).getAttribute(TargetModAttributes.MORTAR_PITCH.get()).setBaseValue((((LivingEntity) looking).getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() + 10)); }
} }
} case 3 -> {
case 3 -> { if (living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() > 31) {
if (((LivingEntity) looking).getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() > 31) { living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).setBaseValue((living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() - 10));
((LivingEntity) looking).getAttribute(TargetModAttributes.MORTAR_PITCH.get()).setBaseValue((((LivingEntity) looking).getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() - 10)); }
} }
} case 4 -> {
case 4 -> { if (living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() > 20.5) {
if (((LivingEntity) looking).getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() > 20.5) { living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).setBaseValue((living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() - 0.5));
((LivingEntity) looking).getAttribute(TargetModAttributes.MORTAR_PITCH.get()).setBaseValue((((LivingEntity) looking).getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() - 0.5)); }
} }
} case 5 -> {
case 5 -> { if (living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() < 88.5) {
if (((LivingEntity) looking).getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() < 88.5) { living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).setBaseValue((living.getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() + 0.5));
((LivingEntity) looking).getAttribute(TargetModAttributes.MORTAR_PITCH.get()).setBaseValue((((LivingEntity) looking).getAttribute(TargetModAttributes.MORTAR_PITCH.get()).getBaseValue() + 0.5)); }
} }
} }
} }
} }
@SubscribeEvent
public static void registerMessage(FMLCommonSetupEvent event) {
TargetMod.addNetworkMessage(MortarGUIButtonMessage.class, MortarGUIButtonMessage::buffer, MortarGUIButtonMessage::new, MortarGUIButtonMessage::handler);
}
} }

View file

@ -24,7 +24,7 @@ import java.util.Map;
import java.util.function.Supplier; import java.util.function.Supplier;
public class GunRecycleGuiMenu extends AbstractContainerMenu implements Supplier<Map<Integer, Slot>> { public class GunRecycleGuiMenu extends AbstractContainerMenu implements Supplier<Map<Integer, Slot>> {
public final static HashMap<String, Object> guistate = new HashMap<>(); public final static HashMap<String, Object> GUI_STATE = new HashMap<>();
public final Level world; public final Level world;
public final Player entity; public final Player entity;
public int x, y, z; public int x, y, z;
@ -49,6 +49,7 @@ public class GunRecycleGuiMenu extends AbstractContainerMenu implements Supplier
this.z = pos.getZ(); this.z = pos.getZ();
access = ContainerLevelAccess.create(world, pos); access = ContainerLevelAccess.create(world, pos);
} }
if (pos != null) { if (pos != null) {
if (extraData.readableBytes() == 1) { // bound to item if (extraData.readableBytes() == 1) { // bound to item
byte hand = extraData.readByte(); byte hand = extraData.readByte();
@ -75,18 +76,23 @@ public class GunRecycleGuiMenu extends AbstractContainerMenu implements Supplier
}); });
} }
} }
this.customSlots.put(0, this.addSlot(new SlotItemHandler(internal, 0, 79, 27) {
this.customSlots.put(0, this.addSlot(new SlotItemHandler(internal, 0, 79, 27) {
@Override @Override
public boolean mayPlace(ItemStack stack) { public boolean mayPlace(ItemStack stack) {
return stack.is(TargetModTags.Items.GUN); return stack.is(TargetModTags.Items.GUN);
} }
})); }));
for (int si = 0; si < 3; ++si)
for (int sj = 0; sj < 9; ++sj) for (int si = 0; si < 3; ++si) {
for (int sj = 0; sj < 9; ++sj) {
this.addSlot(new Slot(inv, sj + (si + 1) * 9, 8 + sj * 18, 84 + si * 18)); this.addSlot(new Slot(inv, sj + (si + 1) * 9, 8 + sj * 18, 84 + si * 18));
for (int si = 0; si < 9; ++si) }
}
for (int si = 0; si < 9; ++si) {
this.addSlot(new Slot(inv, si, 8 + si * 18, 142)); this.addSlot(new Slot(inv, si, 8 + si * 18, 142));
}
} }
@Override @Override

View file

@ -15,7 +15,6 @@ import net.minecraft.world.inventory.ContainerLevelAccess;
import net.minecraft.world.inventory.Slot; import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
@ -28,34 +27,28 @@ import java.util.function.Supplier;
@Mod.EventBusSubscriber @Mod.EventBusSubscriber
public class MortarGUIMenu extends AbstractContainerMenu implements Supplier<Map<Integer, Slot>> { public class MortarGUIMenu extends AbstractContainerMenu implements Supplier<Map<Integer, Slot>> {
public final static HashMap<String, Object> guistate = new HashMap<>(); public final static HashMap<String, Object> GUI_STATE = new HashMap<>();
public final Level world; public final Level world;
public final Player entity; public final Player entity;
public int x, y, z; public int x, y, z;
private ContainerLevelAccess access = ContainerLevelAccess.NULL;
private final IItemHandler internal;
private final Map<Integer, Slot> customSlots = new HashMap<>(); private final Map<Integer, Slot> customSlots = new HashMap<>();
private final boolean bound = false;
private final Supplier<Boolean> boundItemMatcher = null;
private final Entity boundEntity = null;
private final BlockEntity boundBlockEntity = null;
public MortarGUIMenu(int id, Inventory inv, FriendlyByteBuf extraData) { public MortarGUIMenu(int id, Inventory inv, FriendlyByteBuf extraData) {
super(TargetModMenus.MORTAR_GUI.get(), id); super(TargetModMenus.MORTAR_GUI.get(), id);
this.entity = inv.player; this.entity = inv.player;
this.world = inv.player.level(); this.world = inv.player.level();
this.internal = new ItemStackHandler(0); IItemHandler internal = new ItemStackHandler(0);
if (extraData != null) { if (extraData != null) {
BlockPos pos = extraData.readBlockPos(); BlockPos pos = extraData.readBlockPos();
this.x = pos.getX(); this.x = pos.getX();
this.y = pos.getY(); this.y = pos.getY();
this.z = pos.getZ(); this.z = pos.getZ();
access = ContainerLevelAccess.create(world, pos); ContainerLevelAccess access = ContainerLevelAccess.create(world, pos);
} }
Entity looking = TraceTool.findLookingEntity(entity, 6); Entity looking = TraceTool.findLookingEntity(entity, 6);
if (looking == null) return; if (looking == null) return;
if (guistate.get("text:pitch") instanceof EditBox box) if (GUI_STATE.get("text:pitch") instanceof EditBox box)
box.setValue((new java.text.DecimalFormat("##").format(-looking.getXRot()))); box.setValue((new java.text.DecimalFormat("##").format(-looking.getXRot())));
} }
@ -80,7 +73,7 @@ public class MortarGUIMenu extends AbstractContainerMenu implements Supplier<Map
Entity looking = TraceTool.findLookingEntity(entity, 6); Entity looking = TraceTool.findLookingEntity(entity, 6);
if (looking == null) return; if (looking == null) return;
String s = guistate.containsKey("text:pitch") ? ((EditBox) guistate.get("text:pitch")).getValue() : "0"; String s = GUI_STATE.containsKey("text:pitch") ? ((EditBox) GUI_STATE.get("text:pitch")).getValue() : "0";
double converted = 0; double converted = 0;
try { try {
converted = Double.parseDouble(s); converted = Double.parseDouble(s);