diff --git a/build.gradle b/build.gradle index 6b9f7291e..04810967c 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } archivesBaseName = "cgm" -version = "1.3.7-1.19.4" +version = "1.3.8-1.20.1" group = "com.mrcrayfish" java.toolchain.languageVersion = JavaLanguageVersion.of(17) @@ -19,7 +19,7 @@ mixin { } minecraft { - mappings channel: 'official', version: '1.19.4' + mappings channel: 'official', version: '1.20.1' runs { client { @@ -86,15 +86,15 @@ repositories { } dependencies { - minecraft 'net.minecraftforge:forge:1.19.4-45.1.0' - implementation fg.deobf('curse.maven:framework-549225:4718249') + minecraft 'net.minecraftforge:forge:1.20.1-47.2.1' + implementation fg.deobf('curse.maven:framework-549225:4718251') implementation fg.deobf('curse.maven:configured-457570:4462894') - implementation fg.deobf('curse.maven:catalogue-459701:4496718') - implementation fg.deobf('curse.maven:backpacked-352835:4510383') + implementation fg.deobf('curse.maven:catalogue-459701:4766090') + implementation fg.deobf('curse.maven:backpacked-352835:4725665') compileOnly fg.deobf('curse.maven:controllable-317269:4511169') - compileOnly fg.deobf("mezz.jei:jei-1.19.4-common-api:13.1.0.11") - compileOnly fg.deobf("mezz.jei:jei-1.19.4-forge-api:13.1.0.11") - runtimeOnly fg.deobf("mezz.jei:jei-1.19.4-forge:13.1.0.11") + compileOnly fg.deobf("mezz.jei:jei-1.20.1-common-api:15.2.0.27") + compileOnly fg.deobf("mezz.jei:jei-1.20.1-forge-api:15.2.0.27") + runtimeOnly fg.deobf("mezz.jei:jei-1.20.1-forge:15.2.0.27") annotationProcessor('org.spongepowered:mixin:0.8.5:processor') } diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/java/com/mrcrayfish/guns/GunMod.java b/src/main/java/com/mrcrayfish/guns/GunMod.java index 1aac2af98..90ee3574b 100644 --- a/src/main/java/com/mrcrayfish/guns/GunMod.java +++ b/src/main/java/com/mrcrayfish/guns/GunMod.java @@ -74,10 +74,10 @@ public GunMod() bus.addListener(this::onGatherData); DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { FrameworkClientAPI.registerDataLoader(MetaLoader.getInstance()); + ClientHandler.registerCreativeTab(bus); bus.addListener(KeyBinds::registerKeyMappings); bus.addListener(CrosshairHandler::onConfigReload); bus.addListener(ClientHandler::onRegisterReloadListener); - bus.addListener(ClientHandler::onRegisterCreativeTab); bus.addListener(ClientHandler::registerAdditional); }); controllableLoaded = ModList.get().isLoaded("controllable"); diff --git a/src/main/java/com/mrcrayfish/guns/client/BulletTrail.java b/src/main/java/com/mrcrayfish/guns/client/BulletTrail.java index 4a5af6cbe..664eee6b7 100644 --- a/src/main/java/com/mrcrayfish/guns/client/BulletTrail.java +++ b/src/main/java/com/mrcrayfish/guns/client/BulletTrail.java @@ -72,7 +72,7 @@ public void tick() Entity shooter = this.getShooter(); if(shooter instanceof Player && ((Player) shooter).isLocalPlayer()) { - Level world = shooter.level; + Level world = shooter.level(); world.addAlwaysVisibleParticle(this.particleData, true, this.position.x(), this.position.y(), this.position.z(), this.motion.x, this.motion.y, this.motion.z); } diff --git a/src/main/java/com/mrcrayfish/guns/client/ClientHandler.java b/src/main/java/com/mrcrayfish/guns/client/ClientHandler.java index 9d97fd96f..302380aaa 100644 --- a/src/main/java/com/mrcrayfish/guns/client/ClientHandler.java +++ b/src/main/java/com/mrcrayfish/guns/client/ClientHandler.java @@ -1,7 +1,6 @@ package com.mrcrayfish.guns.client; import com.mrcrayfish.guns.GunMod; -import com.mrcrayfish.guns.Reference; import com.mrcrayfish.guns.client.handler.*; import com.mrcrayfish.guns.client.render.gun.ModelOverrides; import com.mrcrayfish.guns.client.render.gun.model.GrenadeLauncherModel; @@ -29,6 +28,7 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.renderer.ItemBlockRenderTypes; import net.minecraft.client.renderer.RenderType; +import net.minecraft.core.registries.Registries; import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -44,25 +44,26 @@ import net.minecraftforge.client.event.RegisterClientReloadListenersEvent; import net.minecraftforge.client.event.ScreenEvent; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.CreativeModeTabEvent; +import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.util.ObfuscationReflectionHelper; +import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; import org.lwjgl.glfw.GLFW; import java.lang.reflect.Field; +import static com.mrcrayfish.guns.Reference.MOD_ID; + /** * Author: MrCrayfish */ -@Mod.EventBusSubscriber(modid = Reference.MOD_ID, value = Dist.CLIENT) -public class ClientHandler -{ +@Mod.EventBusSubscriber(modid = MOD_ID, value = Dist.CLIENT) +public class ClientHandler { private static Field mouseOptionsField; - public static void setup() - { + public static void setup() { MinecraftForge.EVENT_BUS.register(AimingHandler.get()); MinecraftForge.EVENT_BUS.register(BulletTrailRenderingHandler.get()); MinecraftForge.EVENT_BUS.register(CrosshairHandler.get()); @@ -74,8 +75,7 @@ public static void setup() MinecraftForge.EVENT_BUS.register(new PlayerModelHandler()); /* Only register controller events if Controllable is loaded otherwise it will crash */ - if(GunMod.controllableLoaded) - { + if (GunMod.controllableLoaded) { MinecraftForge.EVENT_BUS.register(new ControllerHandler()); GunButtonBindings.register(); } @@ -86,46 +86,38 @@ public static void setup() registerScreenFactories(); } - private static void setupRenderLayers() - { + private static void setupRenderLayers() { ItemBlockRenderTypes.setRenderLayer(ModBlocks.WORKBENCH.get(), RenderType.cutout()); } - private static void registerColors() - { + private static void registerColors() { ItemColor color = (stack, index) -> { - if(!IColored.isDyeable(stack)) - { + if (!IColored.isDyeable(stack)) { return -1; } - if(index == 0 && stack.hasTag() && stack.getTag().contains("Color", Tag.TAG_INT)) - { + if (index == 0 && stack.hasTag() && stack.getTag().contains("Color", Tag.TAG_INT)) { return stack.getTag().getInt("Color"); } - if(index == 0 && stack.getItem() instanceof IAttachment) - { + if (index == 0 && stack.getItem() instanceof IAttachment) { ItemStack renderingWeapon = GunRenderingHandler.get().getRenderingWeapon(); - if(renderingWeapon != null) - { + if (renderingWeapon != null) { return Minecraft.getInstance().getItemColors().getColor(renderingWeapon, index); } } - if(index == 2) // Reticle colour + if (index == 2) // Reticle colour { return PropertyHelper.getReticleColor(stack); } return -1; }; ForgeRegistries.ITEMS.forEach(item -> { - if(item instanceof IColored) - { + if (item instanceof IColored) { Minecraft.getInstance().getItemColors().register(color, item); } }); } - private static void registerModelOverrides() - { + private static void registerModelOverrides() { /* Weapons */ ModelOverrides.register(ModItems.ASSAULT_RIFLE.get(), new SimpleModel(SpecialModels.ASSAULT_RIFLE::getModel)); ModelOverrides.register(ModItems.BAZOOKA.get(), new SimpleModel(SpecialModels.BAZOOKA::getModel)); @@ -138,43 +130,33 @@ private static void registerModelOverrides() ModelOverrides.register(ModItems.SHOTGUN.get(), new SimpleModel(SpecialModels.SHOTGUN::getModel)); } - private static void registerScreenFactories() - { + private static void registerScreenFactories() { MenuScreens.register(ModContainers.WORKBENCH.get(), WorkbenchScreen::new); MenuScreens.register(ModContainers.ATTACHMENTS.get(), AttachmentScreen::new); } @SubscribeEvent - public static void onScreenInit(ScreenEvent.Init.Post event) - { - if(event.getScreen() instanceof MouseSettingsScreen screen) - { - if(mouseOptionsField == null) - { + public static void onScreenInit(ScreenEvent.Init.Post event) { + if (event.getScreen() instanceof MouseSettingsScreen screen) { + if (mouseOptionsField == null) { mouseOptionsField = ObfuscationReflectionHelper.findField(MouseSettingsScreen.class, "f_96218_"); mouseOptionsField.setAccessible(true); } - try - { + try { OptionsList list = (OptionsList) mouseOptionsField.get(screen); //list.addBig(OptionInstance.createBoolean("t", true)); //list.addSmall(GunOptions.ADS_SENSITIVITY, GunOptions.CROSSHAIR); - } - catch(IllegalAccessException e) - { + } catch (IllegalAccessException e) { e.printStackTrace(); } } } @SubscribeEvent - public static void onKeyPressed(InputEvent.Key event) - { + public static void onKeyPressed(InputEvent.Key event) { Minecraft mc = Minecraft.getInstance(); - if(mc.player != null && mc.screen == null && event.getAction() == GLFW.GLFW_PRESS) - { - if(KeyBinds.KEY_ATTACHMENTS.isDown()) - { + if (mc.player != null && mc.screen == null && event.getAction() == GLFW.GLFW_PRESS) { + if (KeyBinds.KEY_ATTACHMENTS.isDown()) { PacketHandler.getPlayChannel().sendToServer(new C2SMessageAttachments()); } /*else if(event.getKey() == GLFW.GLFW_KEY_KP_9) @@ -184,55 +166,49 @@ public static void onKeyPressed(InputEvent.Key event) } } - public static void onRegisterReloadListener(RegisterClientReloadListenersEvent event) - { + public static void onRegisterReloadListener(RegisterClientReloadListenersEvent event) { event.registerReloadListener((ResourceManagerReloadListener) manager -> { PropertyHelper.resetCache(); }); } - public static void registerAdditional(ModelEvent.RegisterAdditional event) - { - event.register(new ResourceLocation(Reference.MOD_ID, "special/test")); + public static void registerAdditional(ModelEvent.RegisterAdditional event) { + event.register(new ResourceLocation(MOD_ID, "special/test")); } - public static void onRegisterCreativeTab(CreativeModeTabEvent.Register event) - { - event.registerCreativeModeTab(new ResourceLocation(Reference.MOD_ID, "creative_tab"), builder -> + public static void registerCreativeTab(IEventBus bus) { + DeferredRegister register = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MOD_ID); + CreativeModeTab.Builder builder = CreativeModeTab.builder(); + builder.title(Component.translatable("itemGroup." + MOD_ID)); + builder.icon(() -> { + ItemStack stack = new ItemStack(ModItems.PISTOL.get()); + stack.getOrCreateTag().putBoolean("IgnoreAmmo", true); + return stack; + }); + builder.displayItems((flags, output) -> { - builder.title(Component.translatable("itemGroup." + Reference.MOD_ID)); - builder.icon(() -> { - ItemStack stack = new ItemStack(ModItems.PISTOL.get()); - stack.getOrCreateTag().putBoolean("IgnoreAmmo", true); - return stack; - }); - builder.displayItems((flags, output) -> + ModItems.REGISTER.getEntries().forEach(registryObject -> { - ModItems.REGISTER.getEntries().forEach(registryObject -> - { - if(registryObject.get() instanceof GunItem item) - { - ItemStack stack = new ItemStack(item); - stack.getOrCreateTag().putInt("AmmoCount", item.getGun().getGeneral().getMaxAmmo()); - output.accept(stack); - return; - } - output.accept(registryObject.get()); - }); - CustomGunManager.fill(output); - for(Enchantment enchantment : ForgeRegistries.ENCHANTMENTS) - { - if(enchantment.category == EnchantmentTypes.GUN || enchantment.category == EnchantmentTypes.SEMI_AUTO_GUN) - { - output.accept(EnchantedBookItem.createForEnchantment(new EnchantmentInstance(enchantment, enchantment.getMaxLevel())), CreativeModeTab.TabVisibility.PARENT_TAB_ONLY); - } + if (registryObject.get() instanceof GunItem item) { + ItemStack stack = new ItemStack(item); + stack.getOrCreateTag().putInt("AmmoCount", item.getGun().getGeneral().getMaxAmmo()); + output.accept(stack); + return; } + output.accept(registryObject.get()); }); + CustomGunManager.fill(output); + for (Enchantment enchantment : ForgeRegistries.ENCHANTMENTS) { + if (enchantment.category == EnchantmentTypes.GUN || enchantment.category == EnchantmentTypes.SEMI_AUTO_GUN) { + output.accept(EnchantedBookItem.createForEnchantment(new EnchantmentInstance(enchantment, enchantment.getMaxLevel())), CreativeModeTab.TabVisibility.PARENT_TAB_ONLY); + } + } }); + register.register("creative_tab", builder::build); + register.register(bus); } - public static Screen createEditorScreen(IEditorMenu menu) - { + public static Screen createEditorScreen(IEditorMenu menu) { return new EditorScreen(Minecraft.getInstance().screen, menu); } diff --git a/src/main/java/com/mrcrayfish/guns/client/handler/BulletTrailRenderingHandler.java b/src/main/java/com/mrcrayfish/guns/client/handler/BulletTrailRenderingHandler.java index 4a696d5e7..5ada104ad 100644 --- a/src/main/java/com/mrcrayfish/guns/client/handler/BulletTrailRenderingHandler.java +++ b/src/main/java/com/mrcrayfish/guns/client/handler/BulletTrailRenderingHandler.java @@ -165,7 +165,7 @@ private void renderBulletTrail(BulletTrail trail, PoseStack poseStack, float del poseStack.mulPose(Axis.YP.rotationDegrees((trail.getAge() + deltaTicks) * (float) 50)); poseStack.scale(0.275F, 0.275F, 0.275F); - int combinedLight = LevelRenderer.getLightColor(entity.level, BlockPos.containing(entity.position())); + int combinedLight = LevelRenderer.getLightColor(entity.level(), BlockPos.containing(entity.position())); ItemStack stack = trail.getItem(); RenderUtil.renderModel(stack, ItemDisplayContext.NONE, poseStack, renderTypeBuffer, combinedLight, OverlayTexture.NO_OVERLAY, null, null); } diff --git a/src/main/java/com/mrcrayfish/guns/client/handler/CrosshairHandler.java b/src/main/java/com/mrcrayfish/guns/client/handler/CrosshairHandler.java index 8ff2623e1..f449c4aa8 100644 --- a/src/main/java/com/mrcrayfish/guns/client/handler/CrosshairHandler.java +++ b/src/main/java/com/mrcrayfish/guns/client/handler/CrosshairHandler.java @@ -142,7 +142,7 @@ public void onRenderOverlay(RenderGuiOverlayEvent.Pre event) if(mc.player.getUseItem().getItem() == Items.SHIELD) return; - PoseStack stack = event.getPoseStack(); + PoseStack stack = event.getGuiGraphics().pose(); stack.pushPose(); int scaledWidth = event.getWindow().getGuiScaledWidth(); int scaledHeight = event.getWindow().getGuiScaledHeight(); diff --git a/src/main/java/com/mrcrayfish/guns/client/handler/GunRenderingHandler.java b/src/main/java/com/mrcrayfish/guns/client/handler/GunRenderingHandler.java index 5daa5bc41..9a155f1f5 100644 --- a/src/main/java/com/mrcrayfish/guns/client/handler/GunRenderingHandler.java +++ b/src/main/java/com/mrcrayfish/guns/client/handler/GunRenderingHandler.java @@ -27,14 +27,12 @@ import com.mrcrayfish.guns.util.GunModifierHelper; import net.minecraft.client.CameraType; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiComponent; -import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.ItemInHandRenderer; import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.block.model.ItemTransforms; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.BlockPos; @@ -63,64 +61,49 @@ import javax.annotation.Nullable; import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Objects; -import java.util.Random; -import java.util.Set; - -public class GunRenderingHandler -{ - private static GunRenderingHandler instance; - - public static GunRenderingHandler get() - { - if(instance == null) - { - instance = new GunRenderingHandler(); - } - return instance; - } +import java.util.*; +public class GunRenderingHandler { public static final ResourceLocation MUZZLE_FLASH_TEXTURE = new ResourceLocation(Reference.MOD_ID, "textures/effect/muzzle_flash.png"); - + public static final ResourceLocation GUI_ICONS_LOCATION = new ResourceLocation( "textures/gui/icons.png"); // Kinda hacky + private static GunRenderingHandler instance; private final Random random = new Random(); private final Set entityIdForMuzzleFlash = new HashSet<>(); private final Set entityIdForDrawnMuzzleFlash = new HashSet<>(); private final Map entityIdToRandomValue = new HashMap<>(); - private int sprintTransition; private int prevSprintTransition; private int sprintCooldown; private float sprintIntensity; - private float offhandTranslate; private float prevOffhandTranslate; - private Field equippedProgressMainHandField; private Field prevEquippedProgressMainHandField; - private float immersiveRoll; private float prevImmersiveRoll; private float fallSway; private float prevFallSway; - @Nullable private ItemStack renderingWeapon; - private GunRenderingHandler() {} + private GunRenderingHandler() { + } + + public static GunRenderingHandler get() { + if (instance == null) { + instance = new GunRenderingHandler(); + } + return instance; + } @Nullable - public ItemStack getRenderingWeapon() - { + public ItemStack getRenderingWeapon() { return this.renderingWeapon; } @SubscribeEvent - public void onTick(TickEvent.ClientTickEvent event) - { - if(event.phase != TickEvent.Phase.END) + public void onTick(TickEvent.ClientTickEvent event) { + if (event.phase != TickEvent.Phase.END) return; this.updateSprinting(); @@ -129,48 +112,39 @@ public void onTick(TickEvent.ClientTickEvent event) this.updateImmersiveCamera(); } - private void updateSprinting() - { + private void updateSprinting() { this.prevSprintTransition = this.sprintTransition; Minecraft mc = Minecraft.getInstance(); - if(mc.player != null && mc.player.isSprinting() && !ModSyncedDataKeys.SHOOTING.getValue(mc.player) && !ModSyncedDataKeys.RELOADING.getValue(mc.player) && !AimingHandler.get().isAiming() && this.sprintCooldown == 0) - { - if(this.sprintTransition < 5) - { + if (mc.player != null && mc.player.isSprinting() && !ModSyncedDataKeys.SHOOTING.getValue(mc.player) && !ModSyncedDataKeys.RELOADING.getValue(mc.player) && !AimingHandler.get().isAiming() && this.sprintCooldown == 0) { + if (this.sprintTransition < 5) { this.sprintTransition++; } - } - else if(this.sprintTransition > 0) - { + } else if (this.sprintTransition > 0) { this.sprintTransition--; } - if(this.sprintCooldown > 0) - { + if (this.sprintCooldown > 0) { this.sprintCooldown--; } } - private void updateMuzzleFlash() - { + private void updateMuzzleFlash() { this.entityIdForMuzzleFlash.removeAll(this.entityIdForDrawnMuzzleFlash); this.entityIdToRandomValue.keySet().removeAll(this.entityIdForDrawnMuzzleFlash); this.entityIdForDrawnMuzzleFlash.clear(); this.entityIdForDrawnMuzzleFlash.addAll(this.entityIdForMuzzleFlash); } - private void updateOffhandTranslate() - { + private void updateOffhandTranslate() { this.prevOffhandTranslate = this.offhandTranslate; Minecraft mc = Minecraft.getInstance(); - if(mc.player == null) + if (mc.player == null) return; boolean down = false; ItemStack heldItem = mc.player.getMainHandItem(); - if(heldItem.getItem() instanceof GunItem) - { + if (heldItem.getItem() instanceof GunItem) { Gun modifiedGun = ((GunItem) heldItem.getItem()).getModifiedGun(heldItem); down = !modifiedGun.getGeneral().getGripType().getHeldAnimation().canRenderOffhandItem(); } @@ -180,9 +154,8 @@ private void updateOffhandTranslate() } @SubscribeEvent - public void onGunFire(GunFireEvent.Post event) - { - if(!event.isClient()) + public void onGunFire(GunFireEvent.Post event) { + if (!event.isClient()) return; this.sprintTransition = 0; @@ -191,14 +164,12 @@ public void onGunFire(GunFireEvent.Post event) ItemStack heldItem = event.getStack(); GunItem gunItem = (GunItem) heldItem.getItem(); Gun modifiedGun = gunItem.getModifiedGun(heldItem); - if(modifiedGun.getDisplay().getFlash() != null) - { + if (modifiedGun.getDisplay().getFlash() != null) { this.showMuzzleFlashForPlayer(Minecraft.getInstance().player.getId()); } } - public void showMuzzleFlashForPlayer(int entityId) - { + public void showMuzzleFlashForPlayer(int entityId) { this.entityIdForMuzzleFlash.add(entityId); this.entityIdToRandomValue.put(entityId, this.random.nextFloat()); } @@ -210,24 +181,23 @@ public void showMuzzleFlashForPlayer(int entityId) * avoids having to render the game twice, which saves a lot of performance. */ @SubscribeEvent - public void onComputeFov(ViewportEvent.ComputeFov event) - { + public void onComputeFov(ViewportEvent.ComputeFov event) { // We only want to modify the FOV of the viewport for rendering hand/items in first person - if(event.usedConfiguredFov()) + if (event.usedConfiguredFov()) return; // Test if the gun has a scope LocalPlayer player = Objects.requireNonNull(Minecraft.getInstance().player); ItemStack heldItem = player.getMainHandItem(); - if(!(heldItem.getItem() instanceof GunItem gunItem)) + if (!(heldItem.getItem() instanceof GunItem gunItem)) return; Gun modifiedGun = gunItem.getModifiedGun(heldItem); - if(!modifiedGun.canAimDownSight()) + if (!modifiedGun.canAimDownSight()) return; // Change the FOV of the first person viewport based on the scope and aim progress - if(AimingHandler.get().getNormalisedAdsProgress() <= 0) + if (AimingHandler.get().getNormalisedAdsProgress() <= 0) return; // Calculate the time curve @@ -242,18 +212,15 @@ public void onComputeFov(ViewportEvent.ComputeFov event) } @SubscribeEvent - public void onRenderOverlay(RenderHandEvent event) - { + public void onRenderOverlay(RenderHandEvent event) { PoseStack poseStack = event.getPoseStack(); boolean right = Minecraft.getInstance().options.mainHand().get() == HumanoidArm.RIGHT ? event.getHand() == InteractionHand.MAIN_HAND : event.getHand() == InteractionHand.OFF_HAND; HumanoidArm hand = right ? HumanoidArm.RIGHT : HumanoidArm.LEFT; ItemStack heldItem = event.getItemStack(); - if(event.getHand() == InteractionHand.OFF_HAND) - { - if(heldItem.getItem() instanceof GunItem) - { + if (event.getHand() == InteractionHand.OFF_HAND) { + if (heldItem.getItem() instanceof GunItem) { event.setCanceled(true); return; } @@ -262,11 +229,9 @@ public void onRenderOverlay(RenderHandEvent event) poseStack.translate(0, offhand * -0.6F, 0); Player player = Minecraft.getInstance().player; - if(player != null && player.getMainHandItem().getItem() instanceof GunItem) - { + if (player != null && player.getMainHandItem().getItem() instanceof GunItem) { Gun modifiedGun = ((GunItem) player.getMainHandItem().getItem()).getModifiedGun(player.getMainHandItem()); - if(!modifiedGun.getGeneral().getGripType().getHeldAnimation().canRenderOffhandItem()) - { + if (!modifiedGun.getGeneral().getGripType().getHeldAnimation().canRenderOffhandItem()) { return; } } @@ -275,8 +240,7 @@ public void onRenderOverlay(RenderHandEvent event) poseStack.translate(0, -1 * AimingHandler.get().getNormalisedAdsProgress(), 0); } - if(!(heldItem.getItem() instanceof GunItem gunItem)) - { + if (!(heldItem.getItem() instanceof GunItem gunItem)) { return; } @@ -284,16 +248,14 @@ public void onRenderOverlay(RenderHandEvent event) event.setCanceled(true); ItemStack overrideModel = ItemStack.EMPTY; - if(heldItem.getTag() != null) - { - if(heldItem.getTag().contains("Model", Tag.TAG_COMPOUND)) - { + if (heldItem.getTag() != null) { + if (heldItem.getTag().contains("Model", Tag.TAG_COMPOUND)) { overrideModel = ItemStack.of(heldItem.getTag().getCompound("Model")); } } LocalPlayer player = Objects.requireNonNull(Minecraft.getInstance().player); - BakedModel model = Minecraft.getInstance().getItemRenderer().getModel(overrideModel.isEmpty() ? heldItem : overrideModel, player.level, player, 0); + BakedModel model = Minecraft.getInstance().getItemRenderer().getModel(overrideModel.isEmpty() ? heldItem : overrideModel, player.level(), player, 0); float scaleX = model.getTransforms().firstPersonRightHand.scale.x(); float scaleY = model.getTransforms().firstPersonRightHand.scale.y(); float scaleZ = model.getTransforms().firstPersonRightHand.scale.z(); @@ -304,10 +266,8 @@ public void onRenderOverlay(RenderHandEvent event) poseStack.pushPose(); Gun modifiedGun = gunItem.getModifiedGun(heldItem); - if(AimingHandler.get().getNormalisedAdsProgress() > 0 && modifiedGun.canAimDownSight()) - { - if(event.getHand() == InteractionHand.MAIN_HAND) - { + if (AimingHandler.get().getNormalisedAdsProgress() > 0 && modifiedGun.canAimDownSight()) { + if (event.getHand() == InteractionHand.MAIN_HAND) { double xOffset = translateX; double yOffset = translateY; double zOffset = translateZ; @@ -325,8 +285,7 @@ public void onRenderOverlay(RenderHandEvent event) /* Creates the required offsets to position the scope into the middle of the screen. */ Scope scope = Gun.getScope(heldItem); - if(modifiedGun.canAttachType(IAttachment.Type.SCOPE) && scope != null) - { + if (modifiedGun.canAttachType(IAttachment.Type.SCOPE) && scope != null) { /* Translate to the mounting position of scopes */ Vec3 scopePosition = PropertyHelper.getAttachmentPosition(heldItem, modifiedGun, IAttachment.Type.SCOPE).subtract(gunOrigin); xOffset += scopePosition.x * 0.0625 * scaleX; @@ -341,9 +300,7 @@ public void onRenderOverlay(RenderHandEvent event) xOffset += scopeCamera.x * 0.0625 * scaleX * scopeScale.x; yOffset += scopeCamera.y * 0.0625 * scaleY * scopeScale.y; zOffset += scopeCamera.z * 0.0625 * scaleZ * scopeScale.z; - } - else - { + } else { /* Translate to iron sight */ Vec3 ironSightCamera = PropertyHelper.getIronSightCamera(heldItem, modifiedGun, gunOrigin).subtract(gunOrigin); xOffset += ironSightCamera.x * 0.0625 * scaleX; @@ -351,8 +308,7 @@ public void onRenderOverlay(RenderHandEvent event) zOffset += ironSightCamera.z * 0.0625 * scaleZ; /* Need to add this to ensure old method still works */ - if(PropertyHelper.isLegacyIronSight(heldItem)) - { + if (PropertyHelper.isLegacyIronSight(heldItem)) { zOffset += 0.72; } } @@ -395,10 +351,10 @@ public void onRenderOverlay(RenderHandEvent event) this.applyShieldTransforms(poseStack, player, modifiedGun, event.getPartialTick()); /* Determines the lighting for the weapon. Weapon will appear bright from muzzle flash or light sources */ - int blockLight = player.isOnFire() ? 15 : player.level.getBrightness(LightLayer.BLOCK, BlockPos.containing(player.getEyePosition(event.getPartialTick()))); + int blockLight = player.isOnFire() ? 15 : player.level().getBrightness(LightLayer.BLOCK, BlockPos.containing(player.getEyePosition(event.getPartialTick()))); blockLight += (this.entityIdForMuzzleFlash.contains(player.getId()) ? 3 : 0); blockLight = Math.min(blockLight, 15); - int packedLight = LightTexture.pack(blockLight, player.level.getBrightness(LightLayer.SKY, BlockPos.containing(player.getEyePosition(event.getPartialTick())))); + int packedLight = LightTexture.pack(blockLight, player.level().getBrightness(LightLayer.SKY, BlockPos.containing(player.getEyePosition(event.getPartialTick())))); /* Renders the first persons arms from the grip type of the weapon */ poseStack.pushPose(); @@ -412,11 +368,9 @@ public void onRenderOverlay(RenderHandEvent event) poseStack.popPose(); } - private void applyBobbingTransforms(PoseStack poseStack, float partialTicks) - { + private void applyBobbingTransforms(PoseStack poseStack, float partialTicks) { Minecraft mc = Minecraft.getInstance(); - if(mc.options.bobView().get() && mc.getCameraEntity() instanceof Player player) - { + if (mc.options.bobView().get() && mc.getCameraEntity() instanceof Player player) { float deltaDistanceWalked = player.walkDist - player.walkDistO; float distanceWalked = -(player.walkDist + deltaDistanceWalked * partialTicks); float bobbing = Mth.lerp(partialTicks, player.oBob, player.bob); @@ -438,10 +392,8 @@ private void applyBobbingTransforms(PoseStack poseStack, float partialTicks) } } - private void applyAimingTransforms(PoseStack poseStack, ItemStack heldItem, Gun modifiedGun, float x, float y, float z, int offset) - { - if(!Config.CLIENT.display.oldAnimations.get()) - { + private void applyAimingTransforms(PoseStack poseStack, ItemStack heldItem, Gun modifiedGun, float x, float y, float z, int offset) { + if (!Config.CLIENT.display.oldAnimations.get()) { poseStack.translate(x * offset, y, z); poseStack.translate(0, -0.25, 0.25); float aiming = (float) Math.sin(Math.toRadians(AimingHandler.get().getNormalisedAdsProgress() * 180F)); @@ -454,10 +406,8 @@ private void applyAimingTransforms(PoseStack poseStack, ItemStack heldItem, Gun } } - private void applySwayTransforms(PoseStack poseStack, Gun modifiedGun, LocalPlayer player, float x, float y, float z, float partialTicks) - { - if(Config.CLIENT.display.weaponSway.get() && player != null) - { + private void applySwayTransforms(PoseStack poseStack, Gun modifiedGun, LocalPlayer player, float x, float y, float z, float partialTicks) { + if (Config.CLIENT.display.weaponSway.get() && player != null) { poseStack.translate(x, y, z); double zOffset = modifiedGun.getGeneral().getGripType().getHeldAnimation().getFallSwayZOffset(); @@ -481,10 +431,8 @@ private void applySwayTransforms(PoseStack poseStack, Gun modifiedGun, LocalPlay } } - private void applySprintingTransforms(Gun modifiedGun, HumanoidArm hand, PoseStack poseStack, float partialTicks) - { - if(Config.CLIENT.display.sprintAnimation.get() && modifiedGun.getGeneral().getGripType().getHeldAnimation().canApplySprintingAnimation()) - { + private void applySprintingTransforms(Gun modifiedGun, HumanoidArm hand, PoseStack poseStack, float partialTicks) { + if (Config.CLIENT.display.sprintAnimation.get() && modifiedGun.getGeneral().getGripType().getHeldAnimation().canApplySprintingAnimation()) { float leftHanded = hand == HumanoidArm.LEFT ? -1 : 1; float transition = (this.prevSprintTransition + (this.sprintTransition - this.prevSprintTransition) * partialTicks) / 5F; transition = (float) Math.sin((transition * Math.PI) / 2); @@ -494,19 +442,16 @@ private void applySprintingTransforms(Gun modifiedGun, HumanoidArm hand, PoseSta } } - private void applyReloadTransforms(PoseStack poseStack, float partialTicks) - { + private void applyReloadTransforms(PoseStack poseStack, float partialTicks) { float reloadProgress = ReloadHandler.get().getReloadProgress(partialTicks); poseStack.translate(0, 0.35 * reloadProgress, 0); poseStack.translate(0, 0, -0.1 * reloadProgress); poseStack.mulPose(Axis.XP.rotationDegrees(45F * reloadProgress)); } - private void applyRecoilTransforms(PoseStack poseStack, ItemStack item, Gun gun) - { + private void applyRecoilTransforms(PoseStack poseStack, ItemStack item, Gun gun) { double recoilNormal = RecoilHandler.get().getGunRecoilNormal(); - if(Gun.hasAttachmentEquipped(item, gun, IAttachment.Type.SCOPE)) - { + if (Gun.hasAttachmentEquipped(item, gun, IAttachment.Type.SCOPE)) { recoilNormal -= recoilNormal * (0.5 * AimingHandler.get().getNormalisedAdsProgress()); } float kickReduction = 1.0F - GunModifierHelper.getKickReduction(item); @@ -523,10 +468,8 @@ private void applyRecoilTransforms(PoseStack poseStack, ItemStack item, Gun gun) poseStack.translate(0, 0, -0.15); } - private void applyShieldTransforms(PoseStack poseStack, LocalPlayer player, Gun modifiedGun, float partialTick) - { - if(player.isUsingItem() && player.getOffhandItem().getItem() == Items.SHIELD && modifiedGun.getGeneral().getGripType() == GripType.ONE_HANDED) - { + private void applyShieldTransforms(PoseStack poseStack, LocalPlayer player, Gun modifiedGun, float partialTick) { + if (player.isUsingItem() && player.getOffhandItem().getItem() == Items.SHIELD && modifiedGun.getGeneral().getGripType() == GripType.ONE_HANDED) { double time = Mth.clamp((player.getTicksUsingItem() + partialTick), 0.0, 4.0) / 4.0; poseStack.translate(0, 0.35 * time, 0); poseStack.mulPose(Axis.XP.rotationDegrees(45F * (float) time)); @@ -534,37 +477,33 @@ private void applyShieldTransforms(PoseStack poseStack, LocalPlayer player, Gun } @SubscribeEvent - public void onTick(TickEvent.RenderTickEvent event) - { - if(event.phase.equals(TickEvent.Phase.START)) + public void onTick(TickEvent.RenderTickEvent event) { + if (event.phase.equals(TickEvent.Phase.START)) return; Minecraft mc = Minecraft.getInstance(); - if(!mc.isWindowActive()) + if (!mc.isWindowActive()) return; Player player = mc.player; - if(player == null) + if (player == null) return; - if(Minecraft.getInstance().options.getCameraType() != CameraType.FIRST_PERSON) + if (Minecraft.getInstance().options.getCameraType() != CameraType.FIRST_PERSON) return; ItemStack heldItem = player.getItemInHand(InteractionHand.MAIN_HAND); - if(heldItem.isEmpty()) + if (heldItem.isEmpty()) return; - if(player.isUsingItem() && player.getUsedItemHand() == InteractionHand.MAIN_HAND && heldItem.getItem() instanceof GrenadeItem) - { - if(!((GrenadeItem) heldItem.getItem()).canCook()) + if (player.isUsingItem() && player.getUsedItemHand() == InteractionHand.MAIN_HAND && heldItem.getItem() instanceof GrenadeItem) { + if (!((GrenadeItem) heldItem.getItem()).canCook()) return; int duration = player.getTicksUsingItem(); - if(duration >= 10) - { + if (duration >= 10) { float cookTime = 1.0F - ((float) (duration - 10) / (float) (player.getUseItem().getUseDuration() - 10)); - if(cookTime > 0.0F) - { + if (cookTime > 0.0F) { float scale = 3; Window window = mc.getWindow(); int i = (int) ((window.getGuiScaledHeight() / 2 - 7 - 60) / scale); @@ -574,13 +513,13 @@ public void onTick(TickEvent.RenderTickEvent event) RenderSystem.defaultBlendFunc(); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShader(GameRenderer::getPositionTexShader); - RenderSystem.setShaderTexture(0, GuiComponent.GUI_ICONS_LOCATION); + RenderSystem.setShaderTexture(0, GUI_ICONS_LOCATION); - PoseStack stack = new PoseStack(); - stack.scale(scale, scale, scale); + GuiGraphics graphics = new GuiGraphics(mc, mc.renderBuffers().bufferSource()); + graphics.pose().scale(scale, scale, scale); int progress = (int) Math.ceil((cookTime) * 17.0F) - 1; - Screen.blit(stack, j, i, 36, 94, 16, 4, 256, 256); - Screen.blit(stack, j, i, 52, 94, progress, 4, 256, 256); + graphics.blit(GUI_ICONS_LOCATION, j, i, 36, 94, 16, 4, 256, 256); + graphics.blit(GUI_ICONS_LOCATION, j, i, 52, 94, progress, 4, 256, 256); RenderSystem.disableBlend(); } @@ -588,14 +527,11 @@ public void onTick(TickEvent.RenderTickEvent event) return; } - if(Config.CLIENT.display.cooldownIndicator.get() && heldItem.getItem() instanceof GunItem) - { + if (Config.CLIENT.display.cooldownIndicator.get() && heldItem.getItem() instanceof GunItem) { Gun gun = ((GunItem) heldItem.getItem()).getGun(); - if(!gun.getGeneral().isAuto()) - { + if (!gun.getGeneral().isAuto()) { float coolDown = player.getCooldowns().getCooldownPercent(heldItem.getItem(), event.renderTickTime); - if(coolDown > 0.0F) - { + if (coolDown > 0.0F) { float scale = 3; Window window = mc.getWindow(); int i = (int) ((window.getGuiScaledHeight() / 2 - 7 - 60) / scale); @@ -605,13 +541,13 @@ public void onTick(TickEvent.RenderTickEvent event) RenderSystem.defaultBlendFunc(); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShader(GameRenderer::getPositionTexShader); - RenderSystem.setShaderTexture(0, GuiComponent.GUI_ICONS_LOCATION); + RenderSystem.setShaderTexture(0, GUI_ICONS_LOCATION); - PoseStack stack = new PoseStack(); - stack.scale(scale, scale, scale); + GuiGraphics graphics = new GuiGraphics(mc, mc.renderBuffers().bufferSource()); + graphics.pose().scale(scale, scale, scale); int progress = (int) Math.ceil((coolDown + 0.05) * 17.0F) - 1; - Screen.blit(stack, j, i, 36, 94, 16, 4, 256, 256); - Screen.blit(stack, j, i, 52, 94, progress, 4, 256, 256); + graphics.blit(GUI_ICONS_LOCATION, j, i, 36, 94, 16, 4, 256, 256); + graphics.blit(GUI_ICONS_LOCATION, j, i, 52, 94, progress, 4, 256, 256); RenderSystem.disableBlend(); } @@ -619,30 +555,23 @@ public void onTick(TickEvent.RenderTickEvent event) } } - public void applyWeaponScale(ItemStack heldItem, PoseStack stack) - { - if(heldItem.getTag() != null) - { + public void applyWeaponScale(ItemStack heldItem, PoseStack stack) { + if (heldItem.getTag() != null) { CompoundTag compound = heldItem.getTag(); - if(compound.contains("Scale", Tag.TAG_FLOAT)) - { + if (compound.contains("Scale", Tag.TAG_FLOAT)) { float scale = compound.getFloat("Scale"); stack.scale(scale, scale, scale); } } } - public boolean renderWeapon(@Nullable LivingEntity entity, ItemStack stack, ItemDisplayContext display, PoseStack poseStack, MultiBufferSource renderTypeBuffer, int light, float partialTicks) - { - if(stack.getItem() instanceof GunItem) - { + public boolean renderWeapon(@Nullable LivingEntity entity, ItemStack stack, ItemDisplayContext display, PoseStack poseStack, MultiBufferSource renderTypeBuffer, int light, float partialTicks) { + if (stack.getItem() instanceof GunItem) { poseStack.pushPose(); ItemStack model = ItemStack.EMPTY; - if(stack.getTag() != null) - { - if(stack.getTag().contains("Model", Tag.TAG_COMPOUND)) - { + if (stack.getTag() != null) { + if (stack.getTag().contains("Model", Tag.TAG_COMPOUND)) { model = ItemStack.of(stack.getTag().getCompound("Model")); } } @@ -661,39 +590,29 @@ public boolean renderWeapon(@Nullable LivingEntity entity, ItemStack stack, Item return false; } - private void renderGun(@Nullable LivingEntity entity, ItemDisplayContext display, ItemStack stack, PoseStack poseStack, MultiBufferSource renderTypeBuffer, int light, float partialTicks) - { - if(ModelOverrides.hasModel(stack)) - { + private void renderGun(@Nullable LivingEntity entity, ItemDisplayContext display, ItemStack stack, PoseStack poseStack, MultiBufferSource renderTypeBuffer, int light, float partialTicks) { + if (ModelOverrides.hasModel(stack)) { IOverrideModel model = ModelOverrides.getModel(stack); - if(model != null) - { + if (model != null) { model.render(partialTicks, display, stack, ItemStack.EMPTY, entity, poseStack, renderTypeBuffer, light, OverlayTexture.NO_OVERLAY); } - } - else - { - Level level = entity != null ? entity.level : null; + } else { + Level level = entity != null ? entity.level() : null; BakedModel bakedModel = Minecraft.getInstance().getItemRenderer().getModel(stack, level, entity, 0); Minecraft.getInstance().getItemRenderer().render(stack, ItemDisplayContext.NONE, false, poseStack, renderTypeBuffer, light, OverlayTexture.NO_OVERLAY, bakedModel); } } - private void renderAttachments(@Nullable LivingEntity entity, ItemDisplayContext display, ItemStack stack, PoseStack poseStack, MultiBufferSource renderTypeBuffer, int light, float partialTicks) - { - if(stack.getItem() instanceof GunItem) - { + private void renderAttachments(@Nullable LivingEntity entity, ItemDisplayContext display, ItemStack stack, PoseStack poseStack, MultiBufferSource renderTypeBuffer, int light, float partialTicks) { + if (stack.getItem() instanceof GunItem) { Gun modifiedGun = ((GunItem) stack.getItem()).getModifiedGun(stack); CompoundTag gunTag = stack.getOrCreateTag(); CompoundTag attachments = gunTag.getCompound("Attachments"); - for(String tagKey : attachments.getAllKeys()) - { + for (String tagKey : attachments.getAllKeys()) { IAttachment.Type type = IAttachment.Type.byTagKey(tagKey); - if(type != null && modifiedGun.canAttachType(type)) - { + if (type != null && modifiedGun.canAttachType(type)) { ItemStack attachmentStack = Gun.getAttachment(type, stack); - if(!attachmentStack.isEmpty()) - { + if (!attachmentStack.isEmpty()) { poseStack.pushPose(); /* Translates the attachment to a standard position by removing the origin */ @@ -716,13 +635,10 @@ private void renderAttachments(@Nullable LivingEntity entity, ItemDisplayContext poseStack.translate(-center.x, -center.y, -center.z); IOverrideModel model = ModelOverrides.getModel(attachmentStack); - if(model != null) - { + if (model != null) { model.render(partialTicks, display, attachmentStack, stack, entity, poseStack, renderTypeBuffer, light, OverlayTexture.NO_OVERLAY); - } - else - { - Level level = entity != null ? entity.level : null; + } else { + Level level = entity != null ? entity.level() : null; BakedModel bakedModel = Minecraft.getInstance().getItemRenderer().getModel(attachmentStack, level, entity, 0); Minecraft.getInstance().getItemRenderer().render(attachmentStack, ItemDisplayContext.NONE, false, poseStack, renderTypeBuffer, light, OverlayTexture.NO_OVERLAY, GunModel.wrap(bakedModel)); } @@ -734,25 +650,23 @@ private void renderAttachments(@Nullable LivingEntity entity, ItemDisplayContext } } - private void renderMuzzleFlash(@Nullable LivingEntity entity, PoseStack poseStack, MultiBufferSource buffer, ItemStack weapon, ItemDisplayContext display, float partialTicks) - { + private void renderMuzzleFlash(@Nullable LivingEntity entity, PoseStack poseStack, MultiBufferSource buffer, ItemStack weapon, ItemDisplayContext display, float partialTicks) { Gun modifiedGun = ((GunItem) weapon.getItem()).getModifiedGun(weapon); - if(modifiedGun.getDisplay().getFlash() == null) + if (modifiedGun.getDisplay().getFlash() == null) return; - if(display != ItemDisplayContext.FIRST_PERSON_RIGHT_HAND && display != ItemDisplayContext.THIRD_PERSON_RIGHT_HAND && display != ItemDisplayContext.FIRST_PERSON_LEFT_HAND && display != ItemDisplayContext.THIRD_PERSON_LEFT_HAND) + if (display != ItemDisplayContext.FIRST_PERSON_RIGHT_HAND && display != ItemDisplayContext.THIRD_PERSON_RIGHT_HAND && display != ItemDisplayContext.FIRST_PERSON_LEFT_HAND && display != ItemDisplayContext.THIRD_PERSON_LEFT_HAND) return; - if(entity == null || !this.entityIdForMuzzleFlash.contains(entity.getId())) + if (entity == null || !this.entityIdForMuzzleFlash.contains(entity.getId())) return; float randomValue = this.entityIdToRandomValue.get(entity.getId()); this.drawMuzzleFlash(weapon, modifiedGun, randomValue, randomValue >= 0.5F, poseStack, buffer, partialTicks); } - private void drawMuzzleFlash(ItemStack weapon, Gun modifiedGun, float random, boolean flip, PoseStack poseStack, MultiBufferSource buffer, float partialTicks) - { - if(!PropertyHelper.hasMuzzleFlash(weapon, modifiedGun)) + private void drawMuzzleFlash(ItemStack weapon, Gun modifiedGun, float random, boolean flip, PoseStack poseStack, MultiBufferSource buffer, float partialTicks) { + if (!PropertyHelper.hasMuzzleFlash(weapon, modifiedGun)) return; poseStack.pushPose(); @@ -766,8 +680,7 @@ private void drawMuzzleFlash(ItemStack weapon, Gun modifiedGun, float random, bo // Legacy method to move muzzle flash to be at the end of the barrel attachment ItemStack barrelStack = Gun.getAttachment(IAttachment.Type.BARREL, weapon); - if(!barrelStack.isEmpty() && barrelStack.getItem() instanceof IBarrel barrel && !PropertyHelper.isUsingBarrelMuzzleFlash(barrelStack)) - { + if (!barrelStack.isEmpty() && barrelStack.getItem() instanceof IBarrel barrel && !PropertyHelper.isUsingBarrelMuzzleFlash(barrelStack)) { Vec3 scale = PropertyHelper.getAttachmentScale(weapon, modifiedGun, IAttachment.Type.BARREL); double length = barrel.getProperties().getLength(); poseStack.translate(0, 0, -length * 0.0625 * scale.z); @@ -799,14 +712,13 @@ private void drawMuzzleFlash(ItemStack weapon, Gun modifiedGun, float random, bo poseStack.popPose(); } - private void renderReloadArm(PoseStack poseStack, MultiBufferSource buffer, int light, Gun modifiedGun, ItemStack stack, HumanoidArm hand, float translateX) - { + private void renderReloadArm(PoseStack poseStack, MultiBufferSource buffer, int light, Gun modifiedGun, ItemStack stack, HumanoidArm hand, float translateX) { Minecraft mc = Minecraft.getInstance(); - if(mc.player == null || mc.player.tickCount < ReloadHandler.get().getStartReloadTick() || ReloadHandler.get().getReloadTimer() != 5) + if (mc.player == null || mc.player.tickCount < ReloadHandler.get().getStartReloadTick() || ReloadHandler.get().getReloadTimer() != 5) return; Item item = ForgeRegistries.ITEMS.getValue(modifiedGun.getProjectile().getItem()); - if(item == null) + if (item == null) return; poseStack.pushPose(); @@ -817,8 +729,7 @@ private void renderReloadArm(PoseStack poseStack, MultiBufferSource buffer, int float interval = GunEnchantmentHelper.getReloadInterval(stack); float reload = ((mc.player.tickCount - ReloadHandler.get().getStartReloadTick() + mc.getFrameTime()) % interval) / interval; float percent = 1.0F - reload; - if(percent >= 0.5F) - { + if (percent >= 0.5F) { percent = 1.0F - percent; } percent *= 2F; @@ -835,8 +746,7 @@ private void renderReloadArm(PoseStack poseStack, MultiBufferSource buffer, int RenderUtil.renderFirstPersonArm(mc.player, hand.getOpposite(), poseStack, buffer, light); - if(reload < 0.5F) - { + if (reload < 0.5F) { poseStack.pushPose(); poseStack.translate(-side * 5 * 0.0625, 15 * 0.0625, -1 * 0.0625); poseStack.mulPose(Axis.XP.rotationDegrees(180F)); @@ -846,20 +756,15 @@ private void renderReloadArm(PoseStack poseStack, MultiBufferSource buffer, int boolean isModel = model.isGui3d(); this.random.setSeed(Item.getId(item)); int count = Math.min(modifiedGun.getGeneral().getReloadAmount(), 5); - for(int i = 0; i < count; ++i) - { + for (int i = 0; i < count; ++i) { poseStack.pushPose(); - if(i > 0) - { - if(isModel) - { + if (i > 0) { + if (isModel) { float x = (this.random.nextFloat() * 2.0F - 1.0F) * 0.15F; float y = (this.random.nextFloat() * 2.0F - 1.0F) * 0.15F; float z = (this.random.nextFloat() * 2.0F - 1.0F) * 0.15F; poseStack.translate(x, y, z); - } - else - { + } else { float x = (this.random.nextFloat() * 2.0F - 1.0F) * 0.15F * 0.5F; float y = (this.random.nextFloat() * 2.0F - 1.0F) * 0.15F * 0.5F; poseStack.translate(x, y, 0); @@ -869,8 +774,7 @@ private void renderReloadArm(PoseStack poseStack, MultiBufferSource buffer, int RenderUtil.renderModel(ammo, ItemDisplayContext.THIRD_PERSON_LEFT_HAND, poseStack, buffer, light, OverlayTexture.NO_OVERLAY, null); poseStack.popPose(); - if(!isModel) - { + if (!isModel) { poseStack.translate(0.0, 0.0, 0.09375F); } } @@ -881,45 +785,39 @@ private void renderReloadArm(PoseStack poseStack, MultiBufferSource buffer, int /** * A temporary hack to get the equip progress until Forge fixes the issue. + * * @return */ - private float getEquipProgress(float partialTicks) - { - if(this.equippedProgressMainHandField == null) - { + private float getEquipProgress(float partialTicks) { + if (this.equippedProgressMainHandField == null) { this.equippedProgressMainHandField = ObfuscationReflectionHelper.findField(ItemInHandRenderer.class, "f_109302_"); this.equippedProgressMainHandField.setAccessible(true); } - if(this.prevEquippedProgressMainHandField == null) - { + if (this.prevEquippedProgressMainHandField == null) { this.prevEquippedProgressMainHandField = ObfuscationReflectionHelper.findField(ItemInHandRenderer.class, "f_109303_"); this.prevEquippedProgressMainHandField.setAccessible(true); } ItemInHandRenderer firstPersonRenderer = Minecraft.getInstance().getEntityRenderDispatcher().getItemInHandRenderer(); - try - { + try { float equippedProgressMainHand = (float) this.equippedProgressMainHandField.get(firstPersonRenderer); float prevEquippedProgressMainHand = (float) this.prevEquippedProgressMainHandField.get(firstPersonRenderer); return 1.0F - Mth.lerp(partialTicks, prevEquippedProgressMainHand, equippedProgressMainHand); - } - catch(IllegalAccessException e) - { + } catch (IllegalAccessException e) { e.printStackTrace(); } return 0.0F; } - private void updateImmersiveCamera() - { + private void updateImmersiveCamera() { this.prevImmersiveRoll = this.immersiveRoll; this.prevFallSway = this.fallSway; Minecraft mc = Minecraft.getInstance(); - if(mc.player == null) + if (mc.player == null) return; ItemStack heldItem = mc.player.getMainHandItem(); - float targetAngle = heldItem.getItem() instanceof GunItem || !Config.CLIENT.display.restrictCameraRollToWeapons.get() ? mc.player.input.leftImpulse: 0F; + float targetAngle = heldItem.getItem() instanceof GunItem || !Config.CLIENT.display.restrictCameraRollToWeapons.get() ? mc.player.input.leftImpulse : 0F; float speed = mc.player.input.leftImpulse != 0 ? 0.1F : 0.15F; this.immersiveRoll = Mth.lerp(speed, this.immersiveRoll, targetAngle); @@ -933,10 +831,8 @@ private void updateImmersiveCamera() } @SubscribeEvent - public void onCameraSetup(ViewportEvent.ComputeCameraAngles event) - { - if(Config.CLIENT.display.cameraRollEffect.get()) - { + public void onCameraSetup(ViewportEvent.ComputeCameraAngles event) { + if (Config.CLIENT.display.cameraRollEffect.get()) { float roll = (float) Mth.lerp(event.getPartialTick(), this.prevImmersiveRoll, this.immersiveRoll); roll = (float) Math.sin((roll * Math.PI) / 2.0); roll *= Config.CLIENT.display.cameraRollAngle.get().floatValue(); diff --git a/src/main/java/com/mrcrayfish/guns/client/render/entity/GrenadeRenderer.java b/src/main/java/com/mrcrayfish/guns/client/render/entity/GrenadeRenderer.java index ffd3d76e6..f10de8ed1 100644 --- a/src/main/java/com/mrcrayfish/guns/client/render/entity/GrenadeRenderer.java +++ b/src/main/java/com/mrcrayfish/guns/client/render/entity/GrenadeRenderer.java @@ -49,7 +49,7 @@ public void render(GrenadeEntity entity, float entityYaw, float partialTicks, Po poseStack.translate(0.0, 0.5, 0.0); - Minecraft.getInstance().getItemRenderer().renderStatic(entity.getItem(), ItemDisplayContext.NONE, light, OverlayTexture.NO_OVERLAY, poseStack, renderTypeBuffer, entity.level, 0); + Minecraft.getInstance().getItemRenderer().renderStatic(entity.getItem(), ItemDisplayContext.NONE, light, OverlayTexture.NO_OVERLAY, poseStack, renderTypeBuffer, entity.level(), 0); poseStack.popPose(); } } diff --git a/src/main/java/com/mrcrayfish/guns/client/render/entity/MissileRenderer.java b/src/main/java/com/mrcrayfish/guns/client/render/entity/MissileRenderer.java index 3a73ac167..1bd936464 100644 --- a/src/main/java/com/mrcrayfish/guns/client/render/entity/MissileRenderer.java +++ b/src/main/java/com/mrcrayfish/guns/client/render/entity/MissileRenderer.java @@ -42,7 +42,7 @@ public void render(MissileEntity entity, float entityYaw, float partialTicks, Po poseStack.mulPose(Axis.YP.rotationDegrees(180F)); poseStack.mulPose(Axis.YP.rotationDegrees(entityYaw)); poseStack.mulPose(Axis.XP.rotationDegrees(entity.getXRot() - 90)); - Minecraft.getInstance().getItemRenderer().renderStatic(entity.getItem(), ItemDisplayContext.NONE, 15728880, OverlayTexture.NO_OVERLAY, poseStack, renderTypeBuffer, entity.level, 0); + Minecraft.getInstance().getItemRenderer().renderStatic(entity.getItem(), ItemDisplayContext.NONE, 15728880, OverlayTexture.NO_OVERLAY, poseStack, renderTypeBuffer, entity.level(), 0); poseStack.translate(0, -1, 0); RenderUtil.renderModel(SpecialModels.FLAME.getModel(), entity.getItem(), poseStack, renderTypeBuffer, 15728880, OverlayTexture.NO_OVERLAY); poseStack.popPose(); diff --git a/src/main/java/com/mrcrayfish/guns/client/render/entity/ProjectileRenderer.java b/src/main/java/com/mrcrayfish/guns/client/render/entity/ProjectileRenderer.java index dcab3867c..e72a5d8ce 100644 --- a/src/main/java/com/mrcrayfish/guns/client/render/entity/ProjectileRenderer.java +++ b/src/main/java/com/mrcrayfish/guns/client/render/entity/ProjectileRenderer.java @@ -40,14 +40,14 @@ public void render(ProjectileEntity entity, float entityYaw, float partialTicks, { poseStack.mulPose(this.entityRenderDispatcher.cameraOrientation()); poseStack.mulPose(Axis.YP.rotationDegrees(180.0F)); - Minecraft.getInstance().getItemRenderer().renderStatic(entity.getItem(), ItemDisplayContext.GROUND, light, OverlayTexture.NO_OVERLAY, poseStack, renderTypeBuffer, entity.level, 0); + Minecraft.getInstance().getItemRenderer().renderStatic(entity.getItem(), ItemDisplayContext.GROUND, light, OverlayTexture.NO_OVERLAY, poseStack, renderTypeBuffer, entity.level(), 0); } else { poseStack.mulPose(Axis.YP.rotationDegrees(180F)); poseStack.mulPose(Axis.YP.rotationDegrees(entityYaw)); poseStack.mulPose(Axis.XP.rotationDegrees(entity.getXRot())); - Minecraft.getInstance().getItemRenderer().renderStatic(entity.getItem(), ItemDisplayContext.NONE, light, OverlayTexture.NO_OVERLAY, poseStack, renderTypeBuffer, entity.level, 0); + Minecraft.getInstance().getItemRenderer().renderStatic(entity.getItem(), ItemDisplayContext.NONE, light, OverlayTexture.NO_OVERLAY, poseStack, renderTypeBuffer, entity.level(), 0); } poseStack.popPose(); diff --git a/src/main/java/com/mrcrayfish/guns/client/render/entity/ThrowableGrenadeRenderer.java b/src/main/java/com/mrcrayfish/guns/client/render/entity/ThrowableGrenadeRenderer.java index 763da8a80..6d0d19b2b 100644 --- a/src/main/java/com/mrcrayfish/guns/client/render/entity/ThrowableGrenadeRenderer.java +++ b/src/main/java/com/mrcrayfish/guns/client/render/entity/ThrowableGrenadeRenderer.java @@ -57,7 +57,7 @@ public void render(ThrowableGrenadeEntity entity, float entityYaw, float partial poseStack.translate(0.0, 0.5, 0.0); - Minecraft.getInstance().getItemRenderer().renderStatic(entity.getItem(), ItemDisplayContext.NONE, light, OverlayTexture.NO_OVERLAY, poseStack, renderTypeBuffer, entity.level, 0); + Minecraft.getInstance().getItemRenderer().renderStatic(entity.getItem(), ItemDisplayContext.NONE, light, OverlayTexture.NO_OVERLAY, poseStack, renderTypeBuffer, entity.level(), 0); poseStack.popPose(); } diff --git a/src/main/java/com/mrcrayfish/guns/client/render/pose/OneHandedPose.java b/src/main/java/com/mrcrayfish/guns/client/render/pose/OneHandedPose.java index 75471a58d..cf64e9253 100644 --- a/src/main/java/com/mrcrayfish/guns/client/render/pose/OneHandedPose.java +++ b/src/main/java/com/mrcrayfish/guns/client/render/pose/OneHandedPose.java @@ -44,7 +44,7 @@ public void renderFirstPersonArms(Player player, HumanoidArm hand, ItemStack sta { poseStack.mulPose(Axis.YP.rotationDegrees(180F)); - BakedModel model = Minecraft.getInstance().getItemRenderer().getModel(stack, player.level, player, 0); + BakedModel model = Minecraft.getInstance().getItemRenderer().getModel(stack, player.level(), player, 0); float translateX = model.getTransforms().firstPersonRightHand.translation.x(); float translateZ = model.getTransforms().firstPersonRightHand.translation.z(); int side = hand.getOpposite() == HumanoidArm.RIGHT ? 1 : -1; diff --git a/src/main/java/com/mrcrayfish/guns/client/render/pose/TwoHandedPose.java b/src/main/java/com/mrcrayfish/guns/client/render/pose/TwoHandedPose.java index 507fb63b2..14baa3c80 100644 --- a/src/main/java/com/mrcrayfish/guns/client/render/pose/TwoHandedPose.java +++ b/src/main/java/com/mrcrayfish/guns/client/render/pose/TwoHandedPose.java @@ -124,7 +124,7 @@ public void renderFirstPersonArms(Player player, HumanoidArm hand, ItemStack sta { poseStack.mulPose(Axis.YP.rotationDegrees(180F)); - BakedModel model = Minecraft.getInstance().getItemRenderer().getModel(stack, player.level, player, 0); + BakedModel model = Minecraft.getInstance().getItemRenderer().getModel(stack, player.level(), player, 0); float translateX = model.getTransforms().firstPersonRightHand.translation.x(); int side = hand.getOpposite() == HumanoidArm.RIGHT ? 1 : -1; poseStack.translate(translateX * side, 0, 0); diff --git a/src/main/java/com/mrcrayfish/guns/client/screen/AttachmentScreen.java b/src/main/java/com/mrcrayfish/guns/client/screen/AttachmentScreen.java index 6a7159b68..78c842dc6 100644 --- a/src/main/java/com/mrcrayfish/guns/client/screen/AttachmentScreen.java +++ b/src/main/java/com/mrcrayfish/guns/client/screen/AttachmentScreen.java @@ -1,6 +1,5 @@ package com.mrcrayfish.guns.client.screen; -import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; @@ -15,12 +14,11 @@ import com.mrcrayfish.guns.item.attachment.IAttachment; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Tooltip; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.block.model.ItemTransforms; import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.Component; @@ -36,7 +34,6 @@ import net.minecraftforge.fml.ModList; import org.joml.Matrix4f; import org.lwjgl.glfw.GLFW; -import org.lwjgl.opengl.GL11; import java.util.ArrayList; import java.util.Arrays; @@ -46,8 +43,7 @@ /** * Author: MrCrayfish */ -public class AttachmentScreen extends AbstractContainerScreen -{ +public class AttachmentScreen extends AbstractContainerScreen { private static final ResourceLocation GUI_TEXTURES = new ResourceLocation("cgm:textures/gui/attachments.png"); private static final Component CONFIG_TOOLTIP = Component.translatable("cgm.button.config.tooltip"); @@ -62,8 +58,7 @@ public class AttachmentScreen extends AbstractContainerScreen buttons = this.gatherButtons(); - for(int i = 0; i < buttons.size(); i++) - { + for (int i = 0; i < buttons.size(); i++) { MiniButton button = buttons.get(i); - switch(Config.CLIENT.buttonAlignment.get()) - { - case LEFT -> - { + switch (Config.CLIENT.buttonAlignment.get()) { + case LEFT -> { int titleWidth = this.minecraft.font.width(this.title); button.setX(this.leftPos + titleWidth + 8 + 3 + i * 13); } - case RIGHT -> - { + case RIGHT -> { button.setX(this.leftPos + this.imageWidth - 7 - 10 - (buttons.size() - 1 - i) * 13); } } @@ -96,11 +86,9 @@ protected void init() } } - private List gatherButtons() - { + private List gatherButtons() { List buttons = new ArrayList<>(); - if(!Config.CLIENT.hideConfigButton.get()) - { + if (!Config.CLIENT.hideConfigButton.get()) { MiniButton configButton = new MiniButton(0, 0, 192, 0, GUI_TEXTURES, onPress -> this.openConfigScreen()); configButton.setTooltip(Tooltip.create(CONFIG_TOOLTIP)); buttons.add(configButton); @@ -109,160 +97,135 @@ private List gatherButtons() } @Override - public void containerTick() - { + public void containerTick() { super.containerTick(); - if(this.minecraft != null && this.minecraft.player != null) - { - if(!(this.minecraft.player.getMainHandItem().getItem() instanceof GunItem)) - { + if (this.minecraft != null && this.minecraft.player != null) { + if (!(this.minecraft.player.getMainHandItem().getItem() instanceof GunItem)) { Minecraft.getInstance().setScreen(null); } } } @Override - public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTicks) - { - this.renderBackground(poseStack); - super.render(poseStack, mouseX, mouseY, partialTicks); - this.renderTooltip(poseStack, mouseX, mouseY); //Render tool tips + public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) { + this.renderBackground(graphics); + super.render(graphics, mouseX, mouseY, partialTicks); + this.renderTooltip(graphics, mouseX, mouseY); //Render tool tips int startX = (this.width - this.imageWidth) / 2; int startY = (this.height - this.imageHeight) / 2; - for(int i = 0; i < IAttachment.Type.values().length; i++) - { - if(RenderUtil.isMouseWithin(mouseX, mouseY, startX + 7, startY + 16 + i * 18, 18, 18)) - { + for (int i = 0; i < IAttachment.Type.values().length; i++) { + if (RenderUtil.isMouseWithin(mouseX, mouseY, startX + 7, startY + 16 + i * 18, 18, 18)) { IAttachment.Type type = IAttachment.Type.values()[i]; - if(!this.menu.getSlot(i).isActive()) - { - this.renderComponentTooltip(poseStack, Arrays.asList(Component.translatable("slot.cgm.attachment." + type.getTranslationKey()), Component.translatable("slot.cgm.attachment.not_applicable")), mouseX, mouseY); - } - else if(this.menu.getSlot(i) instanceof AttachmentSlot slot && slot.getItem().isEmpty() && !this.isCompatible(this.menu.getCarried(), slot)) - { - this.renderComponentTooltip(poseStack, Arrays.asList(Component.translatable("slot.cgm.attachment.incompatible").withStyle(ChatFormatting.YELLOW)), mouseX, mouseY); - } - else if(this.weaponInventory.getItem(i).isEmpty()) - { - this.renderComponentTooltip(poseStack, Collections.singletonList(Component.translatable("slot.cgm.attachment." + type.getTranslationKey())), mouseX, mouseY); + if (!this.menu.getSlot(i).isActive()) { + graphics.renderComponentTooltip(this.font, Arrays.asList(Component.translatable("slot.cgm.attachment." + type.getTranslationKey()), Component.translatable("slot.cgm.attachment.not_applicable")), mouseX, mouseY); + } else if (this.menu.getSlot(i) instanceof AttachmentSlot slot && slot.getItem().isEmpty() && !this.isCompatible(this.menu.getCarried(), slot)) { + graphics.renderComponentTooltip(this.font, Arrays.asList(Component.translatable("slot.cgm.attachment.incompatible").withStyle(ChatFormatting.YELLOW)), mouseX, mouseY); + } else if (this.weaponInventory.getItem(i).isEmpty()) { + graphics.renderComponentTooltip(this.font, Collections.singletonList(Component.translatable("slot.cgm.attachment." + type.getTranslationKey())), mouseX, mouseY); } } } } @Override - protected void renderLabels(PoseStack poseStack, int mouseX, int mouseY) - { + protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) { Minecraft minecraft = Minecraft.getInstance(); - this.font.draw(poseStack, this.title, (float) this.titleLabelX, (float) this.titleLabelY, 4210752); - this.font.draw(poseStack, this.playerInventory.getDisplayName(), (float) this.inventoryLabelX, (float) this.inventoryLabelY + 19, 4210752); + graphics.drawString(this.font, this.title, this.titleLabelX, this.titleLabelY, 4210752); + graphics.drawString(this.font, this.playerInventory.getDisplayName(), this.inventoryLabelX, this.inventoryLabelY + 19, 4210752); int left = (this.width - this.imageWidth) / 2; int top = (this.height - this.imageHeight) / 2; - GuiComponent.enableScissor(left + 26, top + 17, left + 26 + 142, top + 17 + 70); - poseStack.pushPose(); - poseStack.translate(96, 50, 150); - poseStack.translate(this.windowX + (this.mouseGrabbed && this.mouseGrabbedButton == 0 ? mouseX - this.mouseClickedX : 0), 0, 0); - poseStack.translate(0, this.windowY + (this.mouseGrabbed && this.mouseGrabbedButton == 0 ? mouseY - this.mouseClickedY : 0), 0); - poseStack.mulPose(Axis.XP.rotationDegrees(-30F)); - poseStack.mulPose(Axis.XP.rotationDegrees(this.windowRotationY - (this.mouseGrabbed && this.mouseGrabbedButton == 1 ? mouseY - this.mouseClickedY : 0))); - poseStack.mulPose(Axis.YP.rotationDegrees(this.windowRotationX + (this.mouseGrabbed && this.mouseGrabbedButton == 1 ? mouseX - this.mouseClickedX : 0))); - poseStack.mulPose(Axis.YP.rotationDegrees(150F)); - poseStack.scale(this.windowZoom / 10F, this.windowZoom / 10F, this.windowZoom / 10F); - poseStack.mulPose(Axis.YP.rotationDegrees(90F)); - poseStack.mulPoseMatrix((new Matrix4f()).scaling(1.0F, -1.0F, 1.0F)); - poseStack.scale(90.0F, 90.0F, 90.0F); + graphics.enableScissor(left + 26, top + 17, left + 26 + 142, top + 17 + 70); + graphics.pose().pushPose(); + graphics.pose().translate(96, 50, 150); + graphics.pose().translate(this.windowX + (this.mouseGrabbed && this.mouseGrabbedButton == 0 ? mouseX - this.mouseClickedX : 0), 0, 0); + graphics.pose().translate(0, this.windowY + (this.mouseGrabbed && this.mouseGrabbedButton == 0 ? mouseY - this.mouseClickedY : 0), 0); + graphics.pose().mulPose(Axis.XP.rotationDegrees(-30F)); + graphics.pose().mulPose(Axis.XP.rotationDegrees(this.windowRotationY - (this.mouseGrabbed && this.mouseGrabbedButton == 1 ? mouseY - this.mouseClickedY : 0))); + graphics.pose().mulPose(Axis.YP.rotationDegrees(this.windowRotationX + (this.mouseGrabbed && this.mouseGrabbedButton == 1 ? mouseX - this.mouseClickedX : 0))); + graphics.pose().mulPose(Axis.YP.rotationDegrees(150F)); + graphics.pose().scale(this.windowZoom / 10F, this.windowZoom / 10F, this.windowZoom / 10F); + graphics.pose().mulPose(Axis.YP.rotationDegrees(90F)); + graphics.pose().mulPoseMatrix((new Matrix4f()).scaling(1.0F, -1.0F, 1.0F)); + graphics.pose().scale(90.0F, 90.0F, 90.0F); PoseStack modelStack = RenderSystem.getModelViewStack(); modelStack.pushPose(); - modelStack.mulPoseMatrix(poseStack.last().pose()); + modelStack.mulPoseMatrix(graphics.pose().last().pose()); RenderSystem.applyModelViewMatrix(); MultiBufferSource.BufferSource buffer = this.minecraft.renderBuffers().bufferSource(); GunRenderingHandler.get().renderWeapon(this.minecraft.player, this.minecraft.player.getMainHandItem(), ItemDisplayContext.GROUND, new PoseStack(), buffer, 15728880, 0F); buffer.endBatch(); - poseStack.popPose(); + graphics.pose().popPose(); modelStack.popPose(); RenderSystem.applyModelViewMatrix(); - GuiComponent.disableScissor(); - - if(this.showHelp) - { - poseStack.pushPose(); - poseStack.scale(0.5F, 0.5F, 0.5F); - minecraft.font.draw(poseStack, I18n.get("container.cgm.attachments.window_help"), 56, 38, 0xFFFFFF); - poseStack.popPose(); + graphics.disableScissor(); + + if (this.showHelp) { + graphics.pose().pushPose(); + graphics.pose().scale(0.5F, 0.5F, 0.5F); + graphics.drawString(minecraft.font, I18n.get("container.cgm.attachments.window_help"), 56, 38, 0xFFFFFF); + graphics.pose().popPose(); } } @Override - protected void renderBg(PoseStack poseStack, float partialTicks, int mouseX, int mouseY) - { + protected void renderBg(GuiGraphics graphics, float partialTicks, int mouseX, int mouseY) { RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShaderTexture(0, GUI_TEXTURES); int left = (this.width - this.imageWidth) / 2; int top = (this.height - this.imageHeight) / 2; - this.blit(poseStack, left, top, 0, 0, this.imageWidth, this.imageHeight); + graphics.blit(GUI_TEXTURES, left, top, 0, 0, this.imageWidth, this.imageHeight); /* Draws the icons for each attachment slot. If not applicable * for the weapon, it will draw a cross instead. */ - for(int i = 0; i < IAttachment.Type.values().length; i++) - { - if(!this.canPlaceAttachmentInSlot(this.menu.getCarried(), this.menu.getSlot(i))) - { - this.blit(poseStack, left + 8, top + 17 + i * 18, 176, 0, 16, 16); - } - else if(this.weaponInventory.getItem(i).isEmpty()) - { - this.blit(poseStack, left + 8, top + 17 + i * 18, 176, 16 + i * 16, 16, 16); + for (int i = 0; i < IAttachment.Type.values().length; i++) { + if (!this.canPlaceAttachmentInSlot(this.menu.getCarried(), this.menu.getSlot(i))) { + graphics.blit(GUI_TEXTURES, left + 8, top + 17 + i * 18, 176, 0, 16, 16); + } else if (this.weaponInventory.getItem(i).isEmpty()) { + graphics.blit(GUI_TEXTURES, left + 8, top + 17 + i * 18, 176, 16 + i * 16, 16, 16); } } } - private boolean canPlaceAttachmentInSlot(ItemStack stack, Slot slot) - { - if(!slot.isActive()) return false; + private boolean canPlaceAttachmentInSlot(ItemStack stack, Slot slot) { + if (!slot.isActive()) return false; - if(!slot.equals(this.getSlotUnderMouse())) return true; + if (!slot.equals(this.getSlotUnderMouse())) return true; - if(!slot.getItem().isEmpty()) return true; + if (!slot.getItem().isEmpty()) return true; - if(!(slot instanceof AttachmentSlot s)) return true; + if (!(slot instanceof AttachmentSlot s)) return true; - if(!(stack.getItem() instanceof IAttachment a)) return true; + if (!(stack.getItem() instanceof IAttachment a)) return true; - if(!s.getType().equals(a.getType())) return true; + if (!s.getType().equals(a.getType())) return true; return s.mayPlace(stack); } - private boolean isCompatible(ItemStack stack, AttachmentSlot slot) - { - if(stack.isEmpty()) return true; + private boolean isCompatible(ItemStack stack, AttachmentSlot slot) { + if (stack.isEmpty()) return true; - if(!(stack.getItem() instanceof IAttachment attachment)) return false; + if (!(stack.getItem() instanceof IAttachment attachment)) return false; - if(!attachment.getType().equals(slot.getType())) return true; + if (!attachment.getType().equals(slot.getType())) return true; - if(!attachment.canAttachTo(stack)) return false; + if (!attachment.canAttachTo(stack)) return false; return slot.mayPlace(stack); } @Override - public boolean mouseScrolled(double mouseX, double mouseY, double scroll) - { + public boolean mouseScrolled(double mouseX, double mouseY, double scroll) { int startX = (this.width - this.imageWidth) / 2; int startY = (this.height - this.imageHeight) / 2; - if(RenderUtil.isMouseWithin((int) mouseX, (int) mouseY, startX + 26, startY + 17, 142, 70)) - { - if(scroll < 0 && this.windowZoom > 0) - { + if (RenderUtil.isMouseWithin((int) mouseX, (int) mouseY, startX + 26, startY + 17, 142, 70)) { + if (scroll < 0 && this.windowZoom > 0) { this.showHelp = false; this.windowZoom--; - } - else if(scroll > 0) - { + } else if (scroll > 0) { this.showHelp = false; this.windowZoom++; } @@ -271,15 +234,12 @@ else if(scroll > 0) } @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) - { + public boolean mouseClicked(double mouseX, double mouseY, int button) { int startX = (this.width - this.imageWidth) / 2; int startY = (this.height - this.imageHeight) / 2; - if(RenderUtil.isMouseWithin((int) mouseX, (int) mouseY, startX + 26, startY + 17, 142, 70)) - { - if(!this.mouseGrabbed && (button == GLFW.GLFW_MOUSE_BUTTON_LEFT || button == GLFW.GLFW_MOUSE_BUTTON_RIGHT)) - { + if (RenderUtil.isMouseWithin((int) mouseX, (int) mouseY, startX + 26, startY + 17, 142, 70)) { + if (!this.mouseGrabbed && (button == GLFW.GLFW_MOUSE_BUTTON_LEFT || button == GLFW.GLFW_MOUSE_BUTTON_RIGHT)) { this.mouseGrabbed = true; this.mouseGrabbedButton = button == GLFW.GLFW_MOUSE_BUTTON_RIGHT ? 1 : 0; this.mouseClickedX = (int) mouseX; @@ -292,18 +252,13 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) } @Override - public boolean mouseReleased(double mouseX, double mouseY, int button) - { - if(this.mouseGrabbed) - { - if(this.mouseGrabbedButton == 0 && button == GLFW.GLFW_MOUSE_BUTTON_LEFT) - { + public boolean mouseReleased(double mouseX, double mouseY, int button) { + if (this.mouseGrabbed) { + if (this.mouseGrabbedButton == 0 && button == GLFW.GLFW_MOUSE_BUTTON_LEFT) { this.mouseGrabbed = false; this.windowX += (mouseX - this.mouseClickedX - 1); this.windowY += (mouseY - this.mouseClickedY); - } - else if(mouseGrabbedButton == 1 && button == GLFW.GLFW_MOUSE_BUTTON_RIGHT) - { + } else if (mouseGrabbedButton == 1 && button == GLFW.GLFW_MOUSE_BUTTON_RIGHT) { this.mouseGrabbed = false; this.windowRotationX += (mouseX - this.mouseClickedX); this.windowRotationY -= (mouseY - this.mouseClickedY); @@ -312,16 +267,12 @@ else if(mouseGrabbedButton == 1 && button == GLFW.GLFW_MOUSE_BUTTON_RIGHT) return super.mouseReleased(mouseX, mouseY, button); } - private void openConfigScreen() - { + private void openConfigScreen() { ModList.get().getModContainerById(Reference.MOD_ID).ifPresent(container -> { Screen screen = container.getCustomExtension(ConfigScreenHandler.ConfigScreenFactory.class).map(function -> function.screenFunction().apply(this.minecraft, null)).orElse(null); - if(screen != null) - { + if (screen != null) { this.minecraft.setScreen(screen); - } - else if(this.minecraft != null && this.minecraft.player != null) - { + } else if (this.minecraft != null && this.minecraft.player != null) { MutableComponent modName = Component.literal("Configured"); modName.setStyle(modName.getStyle().withColor(ChatFormatting.YELLOW).withUnderlined(true).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.translatable("cgm.chat.open_curseforge_page"))).withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.curseforge.com/minecraft/mc-mods/configured"))); Component message = Component.translatable("cgm.chat.install_configured", modName); diff --git a/src/main/java/com/mrcrayfish/guns/client/screen/CheckBox.java b/src/main/java/com/mrcrayfish/guns/client/screen/CheckBox.java index 3ed019f32..30c576509 100644 --- a/src/main/java/com/mrcrayfish/guns/client/screen/CheckBox.java +++ b/src/main/java/com/mrcrayfish/guns/client/screen/CheckBox.java @@ -1,8 +1,8 @@ package com.mrcrayfish.guns.client.screen; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.narration.NarrationElementOutput; import net.minecraft.network.chat.Component; @@ -14,49 +14,42 @@ * Author: MrCrayfish */ @OnlyIn(Dist.CLIENT) -public class CheckBox extends AbstractWidget -{ +public class CheckBox extends AbstractWidget { private static final ResourceLocation GUI = new ResourceLocation("cgm:textures/gui/components.png"); private boolean toggled = false; - public CheckBox(int left, int top, Component title) - { + public CheckBox(int left, int top, Component title) { super(left, top, 8, 8, title); } - public void setToggled(boolean toggled) - { - this.toggled = toggled; + public boolean isToggled() { + return this.toggled; } - public boolean isToggled() - { - return this.toggled; + public void setToggled(boolean toggled) { + this.toggled = toggled; } @Override - public void renderWidget(PoseStack poseStack, int mouseX, int mouseY, float partialTicks) - { + public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) { RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShaderTexture(0, GUI); - blit(poseStack, this.getX(), this.getY(), 0, 0, 8, 8); - if(this.toggled) - { - blit(poseStack, this.getX(), this.getY() - 1, 8, 0, 9, 8); + // graphics.blit(int screenX, int screenY, int textureX, int textureY, int textureWidth, int textureHeight); + graphics.blit(GUI, this.getX(), this.getY(), 0, 0, 8, 8); // checkbox background + if (this.toggled) { + graphics.blit(GUI, this.getX(), this.getY() - 1, 8, 0, 9, 8); // the actual checkmark } - drawString(poseStack, Minecraft.getInstance().font, this.getMessage(), this.getX() + 12, this.getY(), 0xFFFFFF); + graphics.drawString(Minecraft.getInstance().font, this.getMessage(), this.getX() + 12, this.getY(), 0xFFFFFF); } @Override - public void onClick(double mouseX, double mouseY) - { + public void onClick(double mouseX, double mouseY) { this.toggled = !this.toggled; } @Override - protected void updateWidgetNarration(NarrationElementOutput output) - { + protected void updateWidgetNarration(NarrationElementOutput output) { this.defaultButtonNarrationText(output); } } \ No newline at end of file diff --git a/src/main/java/com/mrcrayfish/guns/client/screen/WorkbenchScreen.java b/src/main/java/com/mrcrayfish/guns/client/screen/WorkbenchScreen.java index e5034e3bd..c3cadca60 100644 --- a/src/main/java/com/mrcrayfish/guns/client/screen/WorkbenchScreen.java +++ b/src/main/java/com/mrcrayfish/guns/client/screen/WorkbenchScreen.java @@ -22,11 +22,11 @@ import com.mrcrayfish.guns.util.InventoryUtil; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.block.model.ItemTransforms; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.resources.sounds.SimpleSoundInstance; import net.minecraft.core.NonNullList; @@ -34,11 +34,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.item.DyeColor; -import net.minecraft.world.item.DyeItem; -import net.minecraft.world.item.ItemDisplayContext; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; +import net.minecraft.world.item.*; import net.minecraftforge.registries.ForgeRegistries; import org.lwjgl.opengl.GL11; @@ -52,8 +48,7 @@ /** * Author: MrCrayfish */ -public class WorkbenchScreen extends AbstractContainerScreen -{ +public class WorkbenchScreen extends AbstractContainerScreen { private static final ResourceLocation GUI_BASE = new ResourceLocation("cgm:textures/gui/workbench.png"); private static boolean showRemaining = false; @@ -67,89 +62,69 @@ public class WorkbenchScreen extends AbstractContainerScreen private CheckBox checkBoxMaterials; private ItemStack displayStack; - public WorkbenchScreen(WorkbenchContainer container, Inventory playerInventory, Component title) - { + public WorkbenchScreen(WorkbenchContainer container, Inventory playerInventory, Component title) { super(container, playerInventory, title); this.playerInventory = playerInventory; this.workbench = container.getWorkbench(); this.imageWidth = 275; this.imageHeight = 184; this.materials = new ArrayList<>(); - this.createTabs(WorkbenchRecipes.getAll(playerInventory.player.level)); - if(!this.tabs.isEmpty()) - { + this.createTabs(WorkbenchRecipes.getAll(playerInventory.player.level())); + if (!this.tabs.isEmpty()) { this.imageHeight += 28; } } - private void createTabs(NonNullList recipes) - { + private void createTabs(NonNullList recipes) { List weapons = new ArrayList<>(); List attachments = new ArrayList<>(); List ammo = new ArrayList<>(); List misc = new ArrayList<>(); - for(WorkbenchRecipe recipe : recipes) - { + for (WorkbenchRecipe recipe : recipes) { ItemStack output = recipe.getItem(); - if(output.getItem() instanceof GunItem) - { + if (output.getItem() instanceof GunItem) { weapons.add(recipe); - } - else if(output.getItem() instanceof IAttachment) - { + } else if (output.getItem() instanceof IAttachment) { attachments.add(recipe); - } - else if(this.isAmmo(output)) - { + } else if (this.isAmmo(output)) { ammo.add(recipe); - } - else - { + } else { misc.add(recipe); } } - if(!weapons.isEmpty()) - { + if (!weapons.isEmpty()) { ItemStack icon = new ItemStack(ModItems.ASSAULT_RIFLE.get()); icon.getOrCreateTag().putInt("AmmoCount", ModItems.ASSAULT_RIFLE.get().getGun().getGeneral().getMaxAmmo()); this.tabs.add(new Tab(icon, "weapons", weapons)); } - if(!attachments.isEmpty()) - { + if (!attachments.isEmpty()) { this.tabs.add(new Tab(new ItemStack(ModItems.LONG_SCOPE.get()), "attachments", attachments)); } - if(!ammo.isEmpty()) - { + if (!ammo.isEmpty()) { this.tabs.add(new Tab(new ItemStack(ModItems.SHELL.get()), "ammo", ammo)); } - if(!misc.isEmpty()) - { + if (!misc.isEmpty()) { this.tabs.add(new Tab(new ItemStack(Items.BARRIER), "misc", misc)); } - if(!this.tabs.isEmpty()) - { + if (!this.tabs.isEmpty()) { this.currentTab = this.tabs.get(0); } } - private boolean isAmmo(ItemStack stack) - { - if(stack.getItem() instanceof IAmmo) - { + private boolean isAmmo(ItemStack stack) { + if (stack.getItem() instanceof IAmmo) { return true; } ResourceLocation id = ForgeRegistries.ITEMS.getKey(stack.getItem()); Objects.requireNonNull(id); - for(GunItem gunItem : NetworkGunManager.getClientRegisteredGuns()) - { - if(id.equals(gunItem.getModifiedGun(stack).getProjectile().getItem())) - { + for (GunItem gunItem : NetworkGunManager.getClientRegisteredGuns()) { + if (id.equals(gunItem.getModifiedGun(stack).getProjectile().getItem())) { return true; } } @@ -157,34 +132,26 @@ private boolean isAmmo(ItemStack stack) } @Override - public void init() - { + public void init() { super.init(); - if(!this.tabs.isEmpty()) - { + if (!this.tabs.isEmpty()) { this.topPos += 28; } this.addRenderableWidget(Button.builder(Component.literal("<"), button -> { int index = this.currentTab.getCurrentIndex(); - if(index - 1 < 0) - { + if (index - 1 < 0) { this.loadItem(this.currentTab.getRecipes().size() - 1); - } - else - { + } else { this.loadItem(index - 1); } }).pos(this.leftPos + 9, this.topPos + 18).size(15, 20).build()); this.addRenderableWidget(Button.builder(Component.literal(">"), button -> { int index = this.currentTab.getCurrentIndex(); - if(index + 1 >= this.currentTab.getRecipes().size()) - { + if (index + 1 >= this.currentTab.getRecipes().size()) { this.loadItem(0); - } - else - { + } else { this.loadItem(index + 1); } }).pos(this.leftPos + 153, this.topPos + 18).size(15, 20).build()); @@ -202,20 +169,16 @@ public void init() } @Override - public void containerTick() - { + public void containerTick() { super.containerTick(); - for(MaterialItem material : this.materials) - { + for (MaterialItem material : this.materials) { material.tick(); } boolean canCraft = true; - for(MaterialItem material : this.materials) - { - if(!material.isEnabled()) - { + for (MaterialItem material : this.materials) { + if (!material.isEnabled()) { canCraft = false; break; } @@ -225,33 +188,24 @@ public void containerTick() this.updateColor(); } - private void updateColor() - { - if(this.currentTab != null) - { + private void updateColor() { + if (this.currentTab != null) { ItemStack item = this.displayStack; - if(IColored.isDyeable(item)) - { + if (IColored.isDyeable(item)) { IColored colored = (IColored) item.getItem(); - if(!this.workbench.getItem(0).isEmpty()) - { + if (!this.workbench.getItem(0).isEmpty()) { ItemStack dyeStack = this.workbench.getItem(0); - if(dyeStack.getItem() instanceof DyeItem) - { + if (dyeStack.getItem() instanceof DyeItem) { DyeColor color = ((DyeItem) dyeStack.getItem()).getDyeColor(); float[] components = color.getTextureDiffuseColors(); int red = (int) (components[0] * 255F); int green = (int) (components[1] * 255F); int blue = (int) (components[2] * 255F); colored.setColor(item, ((red & 0xFF) << 16) | ((green & 0xFF) << 8) | ((blue & 0xFF))); - } - else - { + } else { colored.removeColor(item); } - } - else - { + } else { colored.removeColor(item); } } @@ -259,15 +213,12 @@ private void updateColor() } @Override - public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) - { + public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) { boolean result = super.mouseClicked(mouseX, mouseY, mouseButton); WorkbenchScreen.showRemaining = this.checkBoxMaterials.isToggled(); - for(int i = 0; i < this.tabs.size(); i++) - { - if(RenderUtil.isMouseWithin((int) mouseX, (int) mouseY, this.leftPos + 28 * i, this.topPos - 28, 28, 28)) - { + for (int i = 0; i < this.tabs.size(); i++) { + if (RenderUtil.isMouseWithin((int) mouseX, (int) mouseY, this.leftPos + 28 * i, this.topPos - 28, 28, 28)) { this.currentTab = this.tabs.get(i); this.loadItem(this.currentTab.getCurrentIndex()); this.minecraft.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); @@ -278,8 +229,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) return result; } - private void loadItem(int index) - { + private void loadItem(int index) { WorkbenchRecipe recipe = this.currentTab.getRecipes().get(index); this.displayStack = recipe.getItem().copy(); this.updateColor(); @@ -287,10 +237,8 @@ private void loadItem(int index) this.materials.clear(); List ingredients = recipe.getMaterials(); - if(ingredients != null) - { - for(WorkbenchIngredient ingredient : ingredients) - { + if (ingredients != null) { + for (WorkbenchIngredient ingredient : ingredients) { MaterialItem item = new MaterialItem(ingredient); item.updateEnabledState(); this.materials.add(item); @@ -301,56 +249,48 @@ private void loadItem(int index) } @Override - public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTicks) - { - this.renderBackground(poseStack); - super.render(poseStack, mouseX, mouseY, partialTicks); - this.renderTooltip(poseStack, mouseX, mouseY); + public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) { + this.renderBackground(graphics); + super.render(graphics, mouseX, mouseY, partialTicks); + this.renderTooltip(graphics, mouseX, mouseY); int startX = this.leftPos; int startY = this.topPos; - for(int i = 0; i < this.tabs.size(); i++) - { - if(RenderUtil.isMouseWithin(mouseX, mouseY, startX + 28 * i, startY - 28, 28, 28)) - { - this.renderTooltip(poseStack, Component.translatable(this.tabs.get(i).getTabKey()), mouseX, mouseY); + for (int i = 0; i < this.tabs.size(); i++) { + if (RenderUtil.isMouseWithin(mouseX, mouseY, startX + 28 * i, startY - 28, 28, 28)) { + this.setTooltipForNextRenderPass(Component.translatable(this.tabs.get(i).getTabKey())); + this.renderTooltip(graphics, mouseX, mouseY); return; } } - for(int i = 0; i < this.filteredMaterials.size(); i++) - { + for (int i = 0; i < this.filteredMaterials.size(); i++) { int itemX = startX + 172; int itemY = startY + i * 19 + 63; - if(RenderUtil.isMouseWithin(mouseX, mouseY, itemX, itemY, 80, 19)) - { + if (RenderUtil.isMouseWithin(mouseX, mouseY, itemX, itemY, 80, 19)) { MaterialItem materialItem = this.filteredMaterials.get(i); - if(materialItem != MaterialItem.EMPTY) - { - this.renderTooltip(poseStack, materialItem.getDisplayStack(), mouseX, mouseY); + if (materialItem != MaterialItem.EMPTY) { + graphics.renderTooltip(this.font, materialItem.getDisplayStack(), mouseX, mouseY); return; } } } - if(RenderUtil.isMouseWithin(mouseX, mouseY, startX + 8, startY + 38, 160, 48)) - { - this.renderTooltip(poseStack, this.displayStack, mouseX, mouseY); + if (RenderUtil.isMouseWithin(mouseX, mouseY, startX + 8, startY + 38, 160, 48)) { + graphics.renderTooltip(this.font, this.displayStack, mouseX, mouseY); } } @Override - protected void renderLabels(PoseStack poseStack, int mouseX, int mouseY) - { + protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) { int offset = this.tabs.isEmpty() ? 0 : 28; - this.font.draw(poseStack, this.title, (float)this.titleLabelX, (float)this.titleLabelY - 28 + offset, 4210752); - this.font.draw(poseStack, this.playerInventory.getDisplayName(), (float)this.inventoryLabelX, (float)this.inventoryLabelY - 9 + offset, 4210752); + graphics.drawString(this.font, this.title, this.titleLabelX, this.titleLabelY - 28 + offset, Color.WHITE.getRGB()); + graphics.drawString(this.font, this.playerInventory.getDisplayName(), this.inventoryLabelX, this.inventoryLabelY - 9 + offset, Color.WHITE.getRGB()); } @Override - protected void renderBg(PoseStack poseStack, float partialTicks, int mouseX, int mouseY) - { + protected void renderBg(GuiGraphics graphics, float partialTicks, int mouseX, int mouseY) { /* Fixes partial ticks to use percentage from 0 to 1 */ partialTicks = Minecraft.getInstance().getFrameTime(); @@ -360,60 +300,53 @@ protected void renderBg(PoseStack poseStack, float partialTicks, int mouseX, int RenderSystem.enableBlend(); /* Draw unselected tabs */ - for(int i = 0; i < this.tabs.size(); i++) - { + for (int i = 0; i < this.tabs.size(); i++) { Tab tab = this.tabs.get(i); - if(tab != this.currentTab) - { + if (tab != this.currentTab) { RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShaderTexture(0, GUI_BASE); - blit(poseStack, startX + 28 * i, startY - 28, 80, 184, 28, 32); - Minecraft.getInstance().getItemRenderer().renderAndDecorateItem(poseStack, tab.getIcon(), startX + 28 * i + 6, startY - 28 + 8); - Minecraft.getInstance().getItemRenderer().renderGuiItemDecorations(poseStack, this.font, tab.getIcon(), startX + 28 * i + 6, startY - 28 + 8, null); + graphics.blit(GUI_BASE, startX + 28 * i, startY - 28, 80, 184, 28, 32); + graphics.renderItem(tab.getIcon(), startX + 28 * i + 6, startY - 28 + 8); } } RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShaderTexture(0, GUI_BASE); - blit(poseStack, startX, startY, 0, 0, 173, 184); - blit(poseStack, startX + 173, startY, 78, 184, 173, 0, 1, 184, 256, 256); - blit(poseStack, startX + 251, startY, 174, 0, 24, 184); - blit(poseStack, startX + 172, startY + 16, 198, 0, 20, 20); + graphics.blit(GUI_BASE, startX, startY, 0, 0, 173, 184); + graphics.blit(GUI_BASE, startX + 173, startY, 78, 184, 173, 0, 1, 184, 256, 256); + graphics.blit(GUI_BASE, startX + 251, startY, 174, 0, 24, 184); + graphics.blit(GUI_BASE, startX + 172, startY + 16, 198, 0, 20, 20); /* Draw selected tab */ - if(this.currentTab != null) - { + if (this.currentTab != null) { int i = this.tabs.indexOf(this.currentTab); int u = i == 0 ? 80 : 108; RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShaderTexture(0, GUI_BASE); - blit(poseStack, startX + 28 * i, startY - 28, u, 214, 28, 32); - Minecraft.getInstance().getItemRenderer().renderAndDecorateItem(poseStack, this.currentTab.getIcon(), startX + 28 * i + 6, startY - 28 + 8); - Minecraft.getInstance().getItemRenderer().renderGuiItemDecorations(poseStack, this.font, this.currentTab.getIcon(), startX + 28 * i + 6, startY - 28 + 8, null); + graphics.blit(GUI_BASE, startX + 28 * i, startY - 28, u, 214, 28, 32); + graphics.renderItem(this.currentTab.getIcon(), startX + 28 * i + 6, startY - 28 + 8); } RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShaderTexture(0, GUI_BASE); - if(this.workbench.getItem(0).isEmpty()) - { - blit(poseStack, startX + 174, startY + 18, 165, 199, 16, 16); + if (this.workbench.getItem(0).isEmpty()) { + graphics.blit(GUI_BASE, startX + 174, startY + 18, 165, 199, 16, 16); } ItemStack currentItem = this.displayStack; StringBuilder builder = new StringBuilder(currentItem.getHoverName().getString()); - if(currentItem.getCount() > 1) - { + if (currentItem.getCount() > 1) { builder.append(ChatFormatting.GOLD); builder.append(ChatFormatting.BOLD); builder.append(" x "); builder.append(currentItem.getCount()); } - drawCenteredString(poseStack, this.font, builder.toString(), startX + 88, startY + 22, Color.WHITE.getRGB()); + graphics.drawCenteredString(this.font, builder.toString(), startX + 88, startY + 22, Color.WHITE.getRGB()); GL11.glEnable(GL11.GL_SCISSOR_TEST); RenderUtil.scissor(startX + 8, startY + 17, 160, 70); @@ -427,7 +360,7 @@ protected void renderBg(PoseStack poseStack, float partialTicks, int mouseX, int modelViewStack.mulPose(Axis.YP.rotationDegrees(Minecraft.getInstance().player.tickCount + partialTicks)); RenderSystem.applyModelViewMatrix(); MultiBufferSource.BufferSource buffer = this.minecraft.renderBuffers().bufferSource(); - Minecraft.getInstance().getItemRenderer().render(currentItem, ItemDisplayContext.FIXED, false, poseStack, buffer, 15728880, OverlayTexture.NO_OVERLAY, RenderUtil.getModel(currentItem)); + Minecraft.getInstance().getItemRenderer().render(currentItem, ItemDisplayContext.FIXED, false, graphics.pose(), buffer, 15728880, OverlayTexture.NO_OVERLAY, RenderUtil.getModel(currentItem)); buffer.endBatch(); } modelViewStack.popPose(); @@ -436,76 +369,64 @@ protected void renderBg(PoseStack poseStack, float partialTicks, int mouseX, int GL11.glDisable(GL11.GL_SCISSOR_TEST); this.filteredMaterials = this.getMaterials(); - for(int i = 0; i < this.filteredMaterials.size(); i++) - { + for (int i = 0; i < this.filteredMaterials.size(); i++) { RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShaderTexture(0, GUI_BASE); MaterialItem materialItem = this.filteredMaterials.get(i); ItemStack stack = materialItem.getDisplayStack(); - if(!stack.isEmpty()) - { + if (!stack.isEmpty()) { Lighting.setupForFlatItems(); - if(materialItem.isEnabled()) - { - this.blit(poseStack, startX + 172, startY + i * 19 + 63, 0, 184, 80, 19); - } - else - { - this.blit(poseStack, startX + 172, startY + i * 19 + 63, 0, 222, 80, 19); + if (materialItem.isEnabled()) { + graphics.blit(GUI_BASE,startX + 172, startY + i * 19 + 63, 0, 184, 80, 19); + } else { + graphics.blit(GUI_BASE,startX + 172, startY + i * 19 + 63, 0, 222, 80, 19); } String name = stack.getHoverName().getString(); - if(this.font.width(name) > 55) - { + if (this.font.width(name) > 55) { name = this.font.plainSubstrByWidth(name, 50).trim() + "..."; } - this.font.draw(poseStack, name, startX + 172 + 22, startY + i * 19 + 6 + 63, Color.WHITE.getRGB()); + graphics.drawString(this.font, name, startX + 172 + 22, startY + i * 19 + 6 + 63, Color.WHITE.getRGB()); - Minecraft.getInstance().getItemRenderer().renderAndDecorateItem(poseStack, stack, startX + 172 + 2, startY + i * 19 + 1 + 63); + graphics.renderItem(stack, startX + 172 + 2, startY + i * 19 + 1 + 63); - if(this.checkBoxMaterials.isToggled()) - { + if (this.checkBoxMaterials.isToggled()) { int count = InventoryUtil.getItemStackAmount(Minecraft.getInstance().player, stack); stack = stack.copy(); stack.setCount(stack.getCount() - count); } - Minecraft.getInstance().getItemRenderer().renderGuiItemDecorations(poseStack, this.font, stack, startX + 172 + 2, startY + i * 19 + 1 + 63, null); + graphics.renderItemDecorations(this.font, stack, startX + 172 + 2, startY + i * 19 + 1 + 63); } } } - private List getMaterials() - { + private List getMaterials() { List materials = NonNullList.withSize(6, MaterialItem.EMPTY); List filteredMaterials = this.materials.stream().filter(materialItem -> this.checkBoxMaterials.isToggled() ? !materialItem.isEnabled() : materialItem != MaterialItem.EMPTY).collect(Collectors.toList()); - for(int i = 0; i < filteredMaterials.size() && i < materials.size(); i++) - { + for (int i = 0; i < filteredMaterials.size() && i < materials.size(); i++) { materials.set(i, filteredMaterials.get(i)); } return materials; } - public List getTabs() - { + public List getTabs() { return ImmutableList.copyOf(this.tabs); } - public static class MaterialItem - { + public static class MaterialItem { public static final MaterialItem EMPTY = new MaterialItem(); - + private final List displayStacks = new ArrayList<>(); private long lastTime = System.currentTimeMillis(); private int displayIndex; private boolean enabled = false; private WorkbenchIngredient ingredient; - private final List displayStacks = new ArrayList<>(); - private MaterialItem() {} + private MaterialItem() { + } - private MaterialItem(WorkbenchIngredient ingredient) - { + private MaterialItem(WorkbenchIngredient ingredient) { this.ingredient = ingredient; Stream.of(ingredient.getItems()).forEach(stack -> { ItemStack displayStack = stack.copy(); @@ -514,77 +435,64 @@ private MaterialItem(WorkbenchIngredient ingredient) }); } - public WorkbenchIngredient getIngredient() - { + public WorkbenchIngredient getIngredient() { return this.ingredient; } - public void tick() - { - if(this.ingredient == null) + public void tick() { + if (this.ingredient == null) return; this.updateEnabledState(); long currentTime = System.currentTimeMillis(); - if(currentTime - this.lastTime >= 1000) - { + if (currentTime - this.lastTime >= 1000) { this.displayIndex = (this.displayIndex + 1) % this.displayStacks.size(); this.lastTime = currentTime; } } - public ItemStack getDisplayStack() - { + public ItemStack getDisplayStack() { return this.ingredient != null ? this.displayStacks.get(this.displayIndex) : ItemStack.EMPTY; } - public void updateEnabledState() - { + public void updateEnabledState() { this.enabled = InventoryUtil.hasWorkstationIngredient(Minecraft.getInstance().player, this.ingredient); } - public boolean isEnabled() - { + public boolean isEnabled() { return this.ingredient == null || this.enabled; } } - private static class Tab - { + private static class Tab { private final ItemStack icon; private final String id; private final List items; private int currentIndex; - public Tab(ItemStack icon, String id, List items) - { + public Tab(ItemStack icon, String id, List items) { this.icon = icon; this.id = id; this.items = items; } - public ItemStack getIcon() - { + public ItemStack getIcon() { return this.icon; } - public String getTabKey() - { + public String getTabKey() { return "gui.cgm.workbench.tab." + this.id; } - public void setCurrentIndex(int currentIndex) - { - this.currentIndex = currentIndex; + public int getCurrentIndex() { + return this.currentIndex; } - public int getCurrentIndex() - { - return this.currentIndex; + public void setCurrentIndex(int currentIndex) { + this.currentIndex = currentIndex; } - public List getRecipes() - { + public List getRecipes() { return this.items; } } diff --git a/src/main/java/com/mrcrayfish/guns/client/screen/widget/MiniButton.java b/src/main/java/com/mrcrayfish/guns/client/screen/widget/MiniButton.java index fa2268dd8..15a60980e 100644 --- a/src/main/java/com/mrcrayfish/guns/client/screen/widget/MiniButton.java +++ b/src/main/java/com/mrcrayfish/guns/client/screen/widget/MiniButton.java @@ -2,6 +2,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.network.chat.CommonComponents; @@ -21,7 +22,7 @@ public MiniButton(int x, int y, int u, int v, ResourceLocation texture, OnPress } @Override - public void renderWidget(PoseStack poseStack, int mouseX, int mouseY, float partialTick) + public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) { RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); @@ -29,10 +30,10 @@ public void renderWidget(PoseStack poseStack, int mouseX, int mouseY, float part RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.enableDepthTest(); - blit(poseStack, this.getX(), this.getY(), this.u, this.v, this.width, this.height); + graphics.blit(texture, this.getX(), this.getY(), this.u, this.v, this.width, this.height); if(this.isHovered) { - fillGradient(poseStack, this.getX(), this.getY(), this.getX() + 10, this.getY() + 10, -2130706433, -2130706433); + graphics.fillGradient(this.getX(), this.getY(), this.getX() + 10, this.getY() + 10, -2130706433, -2130706433); } } } diff --git a/src/main/java/com/mrcrayfish/guns/client/util/RenderUtil.java b/src/main/java/com/mrcrayfish/guns/client/util/RenderUtil.java index 3b7556ca3..3b29d8271 100644 --- a/src/main/java/com/mrcrayfish/guns/client/util/RenderUtil.java +++ b/src/main/java/com/mrcrayfish/guns/client/util/RenderUtil.java @@ -84,7 +84,7 @@ public static void renderModel(ItemStack stack, ItemDisplayContext display, Pose BakedModel model = Minecraft.getInstance().getItemRenderer().getItemModelShaper().getItemModel(stack); if(entity != null) { - model = Minecraft.getInstance().getItemRenderer().getModel(stack, entity.level, entity, 0); + model = Minecraft.getInstance().getItemRenderer().getModel(stack, entity.level(), entity, 0); } renderModel(model, display, stack, poseStack, buffer, light, overlay); } @@ -252,7 +252,7 @@ public static int getItemStackColor(ItemStack stack, ItemStack parent, int tintI public static void applyTransformType(ItemStack stack, PoseStack poseStack, ItemDisplayContext display, @Nullable LivingEntity entity) { - BakedModel model = Minecraft.getInstance().getItemRenderer().getModel(stack, entity != null ? entity.level : null, entity, 0); + BakedModel model = Minecraft.getInstance().getItemRenderer().getModel(stack, entity != null ? entity.level() : null, entity, 0); boolean leftHanded = display == ItemDisplayContext.FIRST_PERSON_LEFT_HAND || display == ItemDisplayContext.THIRD_PERSON_LEFT_HAND; //TODO test diff --git a/src/main/java/com/mrcrayfish/guns/common/ReloadTracker.java b/src/main/java/com/mrcrayfish/guns/common/ReloadTracker.java index 1d0edbed5..3c6c9a74c 100644 --- a/src/main/java/com/mrcrayfish/guns/common/ReloadTracker.java +++ b/src/main/java/com/mrcrayfish/guns/common/ReloadTracker.java @@ -112,14 +112,14 @@ private void increaseAmmo(Player player) double soundY = player.getY() + 1.0; double soundZ = player.getZ(); S2CMessageGunSound message = new S2CMessageGunSound(reloadSound, SoundSource.PLAYERS, (float) soundX, (float) soundY, (float) soundZ, 1.0F, 1.0F, player.getId(), false, true); - PacketHandler.getPlayChannel().sendToNearbyPlayers(() -> LevelLocation.create(player.level, soundX, soundY, soundZ, radius), message); + PacketHandler.getPlayChannel().sendToNearbyPlayers(() -> LevelLocation.create(player.level(), soundX, soundY, soundZ, radius), message); } } @SubscribeEvent public static void onPlayerTick(TickEvent.PlayerTickEvent event) { - if(event.phase == TickEvent.Phase.START && !event.player.level.isClientSide) + if(event.phase == TickEvent.Phase.START && !event.player.level().isClientSide) { Player player = event.player; if(ModSyncedDataKeys.RELOADING.getValue(player)) @@ -160,7 +160,7 @@ public static void onPlayerTick(TickEvent.PlayerTickEvent event) double soundZ = finalPlayer.getZ(); double radius = Config.SERVER.reloadMaxDistance.get(); S2CMessageGunSound messageSound = new S2CMessageGunSound(cockSound, SoundSource.PLAYERS, (float) soundX, (float) soundY, (float) soundZ, 1.0F, 1.0F, finalPlayer.getId(), false, true); - PacketHandler.getPlayChannel().sendToNearbyPlayers(() -> LevelLocation.create(finalPlayer.level, soundX, soundY, soundZ, radius), messageSound); + PacketHandler.getPlayChannel().sendToNearbyPlayers(() -> LevelLocation.create(finalPlayer.level(), soundX, soundY, soundZ, radius), messageSound); } }); } diff --git a/src/main/java/com/mrcrayfish/guns/common/container/slot/AttachmentSlot.java b/src/main/java/com/mrcrayfish/guns/common/container/slot/AttachmentSlot.java index 50efc833b..4e18256cc 100644 --- a/src/main/java/com/mrcrayfish/guns/common/container/slot/AttachmentSlot.java +++ b/src/main/java/com/mrcrayfish/guns/common/container/slot/AttachmentSlot.java @@ -69,7 +69,7 @@ public void setChanged() { if(this.container.isLoaded()) { - this.player.level.playSound(null, this.player.getX(), this.player.getY() + 1.0, this.player.getZ(), ModSounds.UI_WEAPON_ATTACH.get(), SoundSource.PLAYERS, 0.5F, this.hasItem() ? 1.0F : 0.75F); + this.player.level().playSound(null, this.player.getX(), this.player.getY() + 1.0, this.player.getZ(), ModSounds.UI_WEAPON_ATTACH.get(), SoundSource.PLAYERS, 0.5F, this.hasItem() ? 1.0F : 0.75F); } } diff --git a/src/main/java/com/mrcrayfish/guns/common/network/ServerPlayHandler.java b/src/main/java/com/mrcrayfish/guns/common/network/ServerPlayHandler.java index a6f7581f8..27ccb73ae 100644 --- a/src/main/java/com/mrcrayfish/guns/common/network/ServerPlayHandler.java +++ b/src/main/java/com/mrcrayfish/guns/common/network/ServerPlayHandler.java @@ -78,7 +78,7 @@ public static void handleShoot(C2SMessageShoot message, ServerPlayer player) if(player.getUseItem().getItem() == Items.SHIELD) return; - Level world = player.level; + Level world = player.level(); ItemStack heldItem = player.getItemInHand(InteractionHand.MAIN_HAND); if(heldItem.getItem() instanceof GunItem item && (Gun.hasAmmo(heldItem) || player.isCreative())) { @@ -131,7 +131,7 @@ public static void handleShoot(C2SMessageShoot message, ServerPlayer player) double radius = Config.COMMON.network.projectileTrackingRange.get(); ParticleOptions data = GunEnchantmentHelper.getParticle(heldItem); S2CMessageBulletTrail messageBulletTrail = new S2CMessageBulletTrail(spawnedProjectiles, projectileProps, player.getId(), data); - PacketHandler.getPlayChannel().sendToNearbyPlayers(() -> LevelLocation.create(player.level, spawnX, spawnY, spawnZ, radius), messageBulletTrail); + PacketHandler.getPlayChannel().sendToNearbyPlayers(() -> LevelLocation.create(player.level(), spawnX, spawnY, spawnZ, radius), messageBulletTrail); } MinecraftForge.EVENT_BUS.post(new GunFireEvent.Post(player, heldItem)); @@ -168,7 +168,7 @@ public static void handleShoot(C2SMessageShoot message, ServerPlayer player) double radius = GunModifierHelper.getModifiedFireSoundRadius(heldItem, Config.SERVER.gunShotMaxDistance.get()); boolean muzzle = modifiedGun.getDisplay().getFlash() != null; S2CMessageGunSound messageSound = new S2CMessageGunSound(fireSound, SoundSource.PLAYERS, (float) posX, (float) posY, (float) posZ, volume, pitch, player.getId(), muzzle, false); - PacketHandler.getPlayChannel().sendToNearbyPlayers(() -> LevelLocation.create(player.level, posX, posY, posZ, radius), messageSound); + PacketHandler.getPlayChannel().sendToNearbyPlayers(() -> LevelLocation.create(player.level(), posX, posY, posZ, radius), messageSound); } if(!player.isCreative()) @@ -177,7 +177,7 @@ public static void handleShoot(C2SMessageShoot message, ServerPlayer player) if(!tag.getBoolean("IgnoreAmmo")) { int level = EnchantmentHelper.getItemEnchantmentLevel(ModEnchantments.RECLAIMED.get(), heldItem); - if(level == 0 || player.level.random.nextInt(4 - Mth.clamp(level, 1, 2)) != 0) + if(level == 0 || player.level().random.nextInt(4 - Mth.clamp(level, 1, 2)) != 0) { tag.putInt("AmmoCount", Math.max(0, tag.getInt("AmmoCount") - 1)); } @@ -221,7 +221,7 @@ else if(stack.isEnchanted()) */ public static void handleCraft(ServerPlayer player, ResourceLocation id, BlockPos pos) { - Level world = player.level; + Level world = player.level(); if(player.containerMenu instanceof WorkbenchContainer workbench) { @@ -305,7 +305,8 @@ private static void spawnAmmo(ServerPlayer player, ItemStack stack) player.getInventory().add(stack); if(stack.getCount() > 0) { - player.level.addFreshEntity(new ItemEntity(player.level, player.getX(), player.getY(), player.getZ(), stack.copy())); + Level playerLevel = player.level(); + playerLevel.addFreshEntity(new ItemEntity(playerLevel, player.getX(), player.getY(), player.getZ(), stack.copy())); } } diff --git a/src/main/java/com/mrcrayfish/guns/debug/client/screen/EditorScreen.java b/src/main/java/com/mrcrayfish/guns/debug/client/screen/EditorScreen.java index 8b36bbc39..426d98d8b 100644 --- a/src/main/java/com/mrcrayfish/guns/debug/client/screen/EditorScreen.java +++ b/src/main/java/com/mrcrayfish/guns/debug/client/screen/EditorScreen.java @@ -12,6 +12,7 @@ import com.mrcrayfish.guns.debug.IEditorMenu; import com.mrcrayfish.guns.util.ScreenUtil; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.ContainerObjectSelectionList; @@ -78,13 +79,13 @@ protected void init() } @Override - public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTicks) + public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) { this.drawHeader(this.windowLeft, this.windowTop, this.windowWidth); this.drawBody(this.windowLeft + 4, this.windowTop + 20, this.windowWidth - 8, this.windowHeight - 20); // Remove header height - this.list.render(poseStack, mouseX, mouseY, partialTicks); - super.render(poseStack, mouseX, mouseY, partialTicks); - Screen.drawString(poseStack, this.font, this.getTitle(), this.windowLeft + 5, this.windowTop + 6, 0xFFFFFF); + this.list.render(graphics, mouseX, mouseY, partialTicks); + super.render(graphics, mouseX, mouseY, partialTicks); + graphics.drawString(this.font, this.getTitle(), this.windowLeft + 5, this.windowTop + 6, 0xFFFFFF); } @Override @@ -172,10 +173,10 @@ public int getRowWidth() } @Override - public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTick) + public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) { ScreenUtil.startScissor(this.x0, this.y0, this.x1 - this.x0, this.y1 - this.y0); - super.render(poseStack, mouseX, mouseY, partialTick); + super.render(graphics, mouseX, mouseY, partialTick); ScreenUtil.endScissor(); } } @@ -192,13 +193,13 @@ public PropertyEntry(Component label, AbstractWidget widget) } @Override - public void render(PoseStack poseStack, int index, int top, int left, int rowWidth, int rowHeight, int mouseX, int mouseY, boolean hovered, float partialTicks) + public void render(GuiGraphics graphics, int index, int top, int left, int rowWidth, int rowHeight, int mouseX, int mouseY, boolean hovered, float partialTicks) { - Screen.drawString(poseStack, EditorScreen.this.minecraft.font, this.label, left + 5, top, 0xFFFFFF); + graphics.drawString(EditorScreen.this.getMinecraft().font, this.label, left + 5, top, 0xFFFFFF); this.widget.setX(left); this.widget.setY(top + 10); this.widget.setWidth(rowWidth); - this.widget.render(poseStack, mouseX, mouseY, partialTicks); + this.widget.render(graphics, mouseX, mouseY, partialTicks); } @Override diff --git a/src/main/java/com/mrcrayfish/guns/debug/client/screen/widget/DebugButton.java b/src/main/java/com/mrcrayfish/guns/debug/client/screen/widget/DebugButton.java index 31e2b7b89..e733b0069 100644 --- a/src/main/java/com/mrcrayfish/guns/debug/client/screen/widget/DebugButton.java +++ b/src/main/java/com/mrcrayfish/guns/debug/client/screen/widget/DebugButton.java @@ -2,6 +2,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mrcrayfish.guns.debug.IDebugWidget; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; import net.minecraft.network.chat.Component; @@ -10,26 +11,22 @@ /** * Author: MrCrayfish */ -public class DebugButton extends Button implements IDebugWidget -{ +public class DebugButton extends Button implements IDebugWidget { private final Supplier enabled; - public DebugButton(Component label, OnPress onPress) - { + public DebugButton(Component label, OnPress onPress) { super(0, 0, 0, 20, label, onPress, DEFAULT_NARRATION); this.enabled = () -> true; } - public DebugButton(Component label, OnPress onPress, Supplier enabled) - { + public DebugButton(Component label, OnPress onPress, Supplier enabled) { super(0, 0, 0, 20, label, onPress, DEFAULT_NARRATION); this.enabled = enabled; } @Override - public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTick) - { + public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) { this.active = this.enabled.get(); - super.render(poseStack, mouseX, mouseY, partialTick); + super.render(graphics, mouseX, mouseY, partialTicks); } } diff --git a/src/main/java/com/mrcrayfish/guns/debug/client/screen/widget/DebugSlider.java b/src/main/java/com/mrcrayfish/guns/debug/client/screen/widget/DebugSlider.java index 696783ae4..225723b6e 100644 --- a/src/main/java/com/mrcrayfish/guns/debug/client/screen/widget/DebugSlider.java +++ b/src/main/java/com/mrcrayfish/guns/debug/client/screen/widget/DebugSlider.java @@ -1,9 +1,8 @@ package com.mrcrayfish.guns.debug.client.screen.widget; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; import com.mrcrayfish.guns.debug.IDebugWidget; -import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraftforge.client.gui.widget.ForgeSlider; import org.jetbrains.annotations.NotNull; @@ -13,29 +12,25 @@ /** * Author: MrCrayfish */ -public class DebugSlider extends ForgeSlider implements IDebugWidget -{ +public class DebugSlider extends ForgeSlider implements IDebugWidget { private final Consumer callback; - public DebugSlider(double minValue, double maxValue, double currentValue, double stepSize, int precision, Consumer callback) - { + public DebugSlider(double minValue, double maxValue, double currentValue, double stepSize, int precision, Consumer callback) { super(0, 0, 0, 14, Component.empty(), Component.empty(), minValue, maxValue, currentValue, stepSize, precision, true); this.callback = callback; } @Override - protected void applyValue() - { + protected void applyValue() { this.callback.accept(this.getValue()); } @Override - public void renderWidget(@NotNull PoseStack poseStack, int mouseX, int mouseY, float partialTick) - { + public void renderWidget(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float partialTick) { RenderSystem.setShaderTexture(0, WIDGETS_LOCATION); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); int i = (this.isHoveredOrFocused() ? 2 : 1) * 20; - blit(poseStack, this.getX() + (int) (this.value * (double) (this.width - 8)), this.getY(), 0, 46 + i, 4, this.height); - blit(poseStack, this.getX() + (int) (this.value * (double) (this.width - 8)) + 4, this.getY(), 196, 46 + i, 4, this.height); + graphics.blit(WIDGETS_LOCATION, this.getX() + (int) (this.value * (double) (this.width - 8)), this.getY(), 0, 46 + i, 4, this.height); + graphics.blit(WIDGETS_LOCATION, this.getX() + (int) (this.value * (double) (this.width - 8)) + 4, this.getY(), 196, 46 + i, 4, this.height); } } diff --git a/src/main/java/com/mrcrayfish/guns/entity/MissileEntity.java b/src/main/java/com/mrcrayfish/guns/entity/MissileEntity.java index 30430d5ac..a4091b2a4 100644 --- a/src/main/java/com/mrcrayfish/guns/entity/MissileEntity.java +++ b/src/main/java/com/mrcrayfish/guns/entity/MissileEntity.java @@ -32,16 +32,16 @@ public MissileEntity(EntityType entityType, Level wo @Override protected void onProjectileTick() { - if (this.level.isClientSide) + if (this.level().isClientSide) { for (int i = 5; i > 0; i--) { - this.level.addParticle(ParticleTypes.CLOUD, true, this.getX() - (this.getDeltaMovement().x() / i), this.getY() - (this.getDeltaMovement().y() / i), this.getZ() - (this.getDeltaMovement().z() / i), 0, 0, 0); + this.level().addParticle(ParticleTypes.CLOUD, true, this.getX() - (this.getDeltaMovement().x() / i), this.getY() - (this.getDeltaMovement().y() / i), this.getZ() - (this.getDeltaMovement().z() / i), 0, 0, 0); } - if (this.level.random.nextInt(2) == 0) + if (this.level().random.nextInt(2) == 0) { - this.level.addParticle(ParticleTypes.SMOKE, true, this.getX(), this.getY(), this.getZ(), 0, 0, 0); - this.level.addParticle(ParticleTypes.FLAME, true, this.getX(), this.getY(), this.getZ(), 0, 0, 0); + this.level().addParticle(ParticleTypes.SMOKE, true, this.getX(), this.getY(), this.getZ(), 0, 0, 0); + this.level().addParticle(ParticleTypes.FLAME, true, this.getX(), this.getY(), this.getZ(), 0, 0, 0); } } } diff --git a/src/main/java/com/mrcrayfish/guns/entity/ProjectileEntity.java b/src/main/java/com/mrcrayfish/guns/entity/ProjectileEntity.java index 9f8e3e0c9..268aef6e8 100644 --- a/src/main/java/com/mrcrayfish/guns/entity/ProjectileEntity.java +++ b/src/main/java/com/mrcrayfish/guns/entity/ProjectileEntity.java @@ -60,6 +60,7 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.LeavesBlock; import net.minecraft.world.level.block.TargetBlock; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.FluidState; import net.minecraft.world.phys.AABB; @@ -225,11 +226,11 @@ public void tick() this.updateHeading(); this.onProjectileTick(); - if(!this.level.isClientSide()) + if(!this.level().isClientSide()) { Vec3 startVec = this.position(); Vec3 endVec = startVec.add(this.getDeltaMovement()); - HitResult result = rayTraceBlocks(this.level, new ClipContext(startVec, endVec, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this), IGNORE_LEAVES); + HitResult result = rayTraceBlocks(this.level(), new ClipContext(startVec, endVec, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this), IGNORE_LEAVES); if(result.getType() != HitResult.Type.MISS) { endVec = result.getLocation(); @@ -318,7 +319,7 @@ protected EntityResult findEntityOnPath(Vec3 startVec, Vec3 endVec) Vec3 hitVec = null; Entity hitEntity = null; boolean headshot = false; - List entities = this.level.getEntities(this, this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(1.0), PROJECTILE_TARGETS); + List entities = this.level().getEntities(this, this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(1.0), PROJECTILE_TARGETS); double closestDistance = Double.MAX_VALUE; for(Entity entity : entities) { @@ -345,7 +346,7 @@ protected EntityResult findEntityOnPath(Vec3 startVec, Vec3 endVec) protected List findEntitiesOnPath(Vec3 startVec, Vec3 endVec) { List hitEntities = new ArrayList<>(); - List entities = this.level.getEntities(this, this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(1.0), PROJECTILE_TARGETS); + List entities = this.level().getEntities(this, this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(1.0), PROJECTILE_TARGETS); for(Entity entity : entities) { if(!entity.equals(this.shooter)) @@ -376,7 +377,7 @@ private EntityResult getHitResult(Entity entity, Vec3 startVec, Vec3 endVec) Vec3 grownHitPos = boundingBox.inflate(Config.COMMON.gameplay.growBoundingBoxAmount.get(), 0, Config.COMMON.gameplay.growBoundingBoxAmount.get()).clip(startVec, endVec).orElse(null); if(hitPos == null && grownHitPos != null) { - HitResult raytraceresult = rayTraceBlocks(this.level, new ClipContext(startVec, grownHitPos, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this), IGNORE_LEAVES); + HitResult raytraceresult = rayTraceBlocks(this.level(), new ClipContext(startVec, grownHitPos, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this), IGNORE_LEAVES); if(raytraceresult.getType() == HitResult.Type.BLOCK) { return null; @@ -434,37 +435,37 @@ private void onHit(HitResult result, Vec3 startVec, Vec3 endVec) Vec3 hitVec = result.getLocation(); BlockPos pos = blockHitResult.getBlockPos(); - BlockState state = this.level.getBlockState(pos); + BlockState state = this.level().getBlockState(pos); Block block = state.getBlock(); if(Config.COMMON.gameplay.griefing.enableGlassBreaking.get() && state.is(ModTags.Blocks.FRAGILE)) { - float destroySpeed = state.getDestroySpeed(this.level, pos); + float destroySpeed = state.getDestroySpeed(this.level(), pos); if(destroySpeed >= 0) { float chance = Config.COMMON.gameplay.griefing.fragileBaseBreakChance.get().floatValue() / (destroySpeed + 1); if(this.random.nextFloat() < chance) { - this.level.destroyBlock(pos, Config.COMMON.gameplay.griefing.fragileBlockDrops.get()); + this.level().destroyBlock(pos, Config.COMMON.gameplay.griefing.fragileBlockDrops.get()); } } } - if(!state.getMaterial().isReplaceable()) + if(!state.canBeReplaced()) { this.remove(RemovalReason.KILLED); } if(block instanceof IDamageable) { - ((IDamageable) block).onBlockDamaged(this.level, state, pos, this, this.getDamage(), (int) Math.ceil(this.getDamage() / 2.0) + 1); + ((IDamageable) block).onBlockDamaged(this.level(), state, pos, this, this.getDamage(), (int) Math.ceil(this.getDamage() / 2.0) + 1); } this.onHitBlock(state, pos, blockHitResult.getDirection(), hitVec.x, hitVec.y, hitVec.z); if(block instanceof TargetBlock targetBlock) { - int power = ReflectionUtil.updateTargetBlock(targetBlock, this.level, state, blockHitResult, this); + int power = ReflectionUtil.updateTargetBlock(targetBlock, this.level(), state, blockHitResult, this); if(this.shooter instanceof ServerPlayer serverPlayer) { serverPlayer.awardStat(Stats.TARGET_HIT); @@ -474,18 +475,18 @@ private void onHit(HitResult result, Vec3 startVec, Vec3 endVec) if(block instanceof BellBlock bell) { - bell.attemptToRing(this.level, pos, blockHitResult.getDirection()); + bell.attemptToRing(this.level(), pos, blockHitResult.getDirection()); } int fireStarterLevel = EnchantmentHelper.getItemEnchantmentLevel(ModEnchantments.FIRE_STARTER.get(), this.weapon); if(fireStarterLevel > 0 && Config.COMMON.gameplay.griefing.setFireToBlocks.get()) { BlockPos offsetPos = pos.relative(blockHitResult.getDirection()); - if(BaseFireBlock.canBePlacedAt(this.level, offsetPos, blockHitResult.getDirection())) + if(BaseFireBlock.canBePlacedAt(this.level(), offsetPos, blockHitResult.getDirection())) { - BlockState fireState = BaseFireBlock.getState(this.level, offsetPos); - this.level.setBlock(offsetPos, fireState, 11); - ((ServerLevel) this.level).sendParticles(ParticleTypes.LAVA, hitVec.x - 1.0 + this.random.nextDouble() * 2.0, hitVec.y, hitVec.z - 1.0 + this.random.nextDouble() * 2.0, 4, 0, 0, 0, 0); + BlockState fireState = BaseFireBlock.getState(this.level(), offsetPos); + this.level().setBlock(offsetPos, fireState, 11); + ((ServerLevel) this.level()).sendParticles(ParticleTypes.LAVA, hitVec.x - 1.0 + this.random.nextDouble() * 2.0, hitVec.y, hitVec.z - 1.0 + this.random.nextDouble() * 2.0, 4, 0, 0, 0, 0); } } return; @@ -537,7 +538,7 @@ protected void onHitEntity(Entity entity, Vec3 hitVec, Vec3 startVec, Vec3 endVe damage *= Config.COMMON.gameplay.headShotDamageMultiplier.get(); } - DamageSource source = ModDamageTypes.Sources.projectile(this.level.registryAccess(), this, this.shooter); + DamageSource source = ModDamageTypes.Sources.projectile(this.level().registryAccess(), this, this.shooter); entity.hurt(source, damage); if(this.shooter instanceof Player) @@ -552,7 +553,7 @@ protected void onHitEntity(Entity entity, Vec3 hitVec, Vec3 startVec, Vec3 endVe protected void onHitBlock(BlockState state, BlockPos pos, Direction face, double x, double y, double z) { - PacketHandler.getPlayChannel().sendToTrackingChunk(() -> this.level.getChunkAt(pos), new S2CMessageProjectileHitBlock(x, y, z, pos, face)); + PacketHandler.getPlayChannel().sendToTrackingChunk(() -> this.level().getChunkAt(pos), new S2CMessageProjectileHitBlock(x, y, z, pos, face)); } @Override @@ -672,7 +673,7 @@ public boolean shouldRenderAtSqrDistance(double distance) @Override public void onRemovedFromWorld() { - if(!this.level.isClientSide) + if(!this.level().isClientSide) { PacketHandler.getPlayChannel().sendToNearbyPlayers(this::getDeathTargetPoint, new S2CMessageRemoveProjectile(this.getId())); } @@ -680,7 +681,7 @@ public void onRemovedFromWorld() private LevelLocation getDeathTargetPoint() { - return LevelLocation.create(this.level, this.getX(), this.getY(), this.getZ(), 256); + return LevelLocation.create(this.level(), this.getX(), this.getY(), this.getZ(), 256); } @Override @@ -804,7 +805,7 @@ else if(d13 < d14) */ public static void createExplosion(Entity entity, float radius, boolean forceNone) { - Level world = entity.level; + Level world = entity.level(); if(world.isClientSide()) return; diff --git a/src/main/java/com/mrcrayfish/guns/entity/ThrowableGrenadeEntity.java b/src/main/java/com/mrcrayfish/guns/entity/ThrowableGrenadeEntity.java index a9c4f76a3..aa78bfbdc 100644 --- a/src/main/java/com/mrcrayfish/guns/entity/ThrowableGrenadeEntity.java +++ b/src/main/java/com/mrcrayfish/guns/entity/ThrowableGrenadeEntity.java @@ -55,9 +55,9 @@ public void tick() { this.rotation += speed * 50; } - if (this.level.isClientSide) + if (this.level().isClientSide) { - this.level.addParticle(ParticleTypes.SMOKE, true, this.getX(), this.getY() + 0.25, this.getZ(), 0, 0, 0); + this.level().addParticle(ParticleTypes.SMOKE, true, this.getX(), this.getY() + 0.25, this.getZ(), 0, 0, 0); } } diff --git a/src/main/java/com/mrcrayfish/guns/entity/ThrowableItemEntity.java b/src/main/java/com/mrcrayfish/guns/entity/ThrowableItemEntity.java index 1e689f723..bb787fbfa 100644 --- a/src/main/java/com/mrcrayfish/guns/entity/ThrowableItemEntity.java +++ b/src/main/java/com/mrcrayfish/guns/entity/ThrowableItemEntity.java @@ -102,12 +102,12 @@ protected void onHit(HitResult result) if(this.shouldBounce) { BlockPos resultPos = blockResult.getBlockPos(); - BlockState state = this.level.getBlockState(resultPos); - SoundEvent event = state.getBlock().getSoundType(state, this.level, resultPos, this).getStepSound(); + BlockState state = this.level().getBlockState(resultPos); + SoundEvent event = state.getBlock().getSoundType(state, this.level(), resultPos, this).getStepSound(); double speed = this.getDeltaMovement().length(); if(speed > 0.1) { - this.level.playSound(null, result.getLocation().x, result.getLocation().y, result.getLocation().z, event, SoundSource.AMBIENT, 1.0F, 1.0F); + this.level().playSound(null, result.getLocation().x, result.getLocation().y, result.getLocation().z, event, SoundSource.AMBIENT, 1.0F, 1.0F); } this.bounce(blockResult.getDirection()); } diff --git a/src/main/java/com/mrcrayfish/guns/entity/ThrowableStunGrenadeEntity.java b/src/main/java/com/mrcrayfish/guns/entity/ThrowableStunGrenadeEntity.java index 0d51d3f5a..87434df49 100644 --- a/src/main/java/com/mrcrayfish/guns/entity/ThrowableStunGrenadeEntity.java +++ b/src/main/java/com/mrcrayfish/guns/entity/ThrowableStunGrenadeEntity.java @@ -22,59 +22,50 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.shapes.Shapes; -import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent; +import net.minecraftforge.event.entity.living.LivingChangeTargetEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.network.PacketDistributor; import javax.annotation.Nullable; @Mod.EventBusSubscriber -public class ThrowableStunGrenadeEntity extends ThrowableGrenadeEntity -{ - public ThrowableStunGrenadeEntity(EntityType entityType, Level world) - { +public class ThrowableStunGrenadeEntity extends ThrowableGrenadeEntity { + public ThrowableStunGrenadeEntity(EntityType entityType, Level world) { super(entityType, world); } - public ThrowableStunGrenadeEntity(EntityType entityType, Level world, LivingEntity player) - { + public ThrowableStunGrenadeEntity(EntityType entityType, Level world, LivingEntity player) { super(entityType, world, player); this.setItem(new ItemStack(ModItems.STUN_GRENADE.get())); } - public ThrowableStunGrenadeEntity(Level world, LivingEntity player, int maxCookTime) - { + public ThrowableStunGrenadeEntity(Level world, LivingEntity player, int maxCookTime) { super(ModEntities.THROWABLE_STUN_GRENADE.get(), world, player); this.setItem(new ItemStack(ModItems.STUN_GRENADE.get())); this.setMaxLife(maxCookTime); } @SubscribeEvent - public static void blindMobs(LivingSetAttackTargetEvent event) - { - if(Config.COMMON.stunGrenades.blind.blindMobs.get() && event.getTarget() != null && event.getEntity() instanceof Mob && event.getEntity().hasEffect(ModEffects.BLINDED.get())) - { + public static void blindMobs(LivingChangeTargetEvent event) { + if (Config.COMMON.stunGrenades.blind.blindMobs.get() && event.getOriginalTarget() != null && event.getEntity() instanceof Mob && event.getEntity().hasEffect(ModEffects.BLINDED.get())) { ((Mob) event.getEntity()).setTarget(null); } } @Override - public void onDeath() - { + public void onDeath() { double y = this.getY() + this.getType().getDimensions().height * 0.5; - this.level.playSound(null, this.getX(), y, this.getZ(), ModSounds.ENTITY_STUN_GRENADE_EXPLOSION.get(), SoundSource.BLOCKS, 4, (1 + (level.random.nextFloat() - level.random.nextFloat()) * 0.2F) * 0.7F); - if(this.level.isClientSide) - { + this.level().playSound(null, this.getX(), y, this.getZ(), ModSounds.ENTITY_STUN_GRENADE_EXPLOSION.get(), SoundSource.BLOCKS, 4, (1 + (level().random.nextFloat() - level().random.nextFloat()) * 0.2F) * 0.7F); + if (this.level().isClientSide) { return; } - PacketHandler.getPlayChannel().sendToNearbyPlayers(() -> LevelLocation.create(this.level, this.getX(), y, this.getZ(), 64), new S2CMessageStunGrenade(this.getX(), y, this.getZ())); + PacketHandler.getPlayChannel().sendToNearbyPlayers(() -> LevelLocation.create(this.level(), this.getX(), y, this.getZ(), 64), new S2CMessageStunGrenade(this.getX(), y, this.getZ())); // Calculate bounds of area where potentially effected players my be double diameter = Math.max(Config.COMMON.stunGrenades.deafen.criteria.radius.get(), Config.COMMON.stunGrenades.blind.criteria.radius.get()) * 2 + 1; @@ -89,9 +80,8 @@ public void onDeath() Vec3 grenade = new Vec3(this.getX(), y, this.getZ()); Vec3 eyes, directionGrenade; double distance; - for(LivingEntity entity : this.level.getEntitiesOfClass(LivingEntity.class, new AABB(minX, minY, minZ, maxX, maxY, maxZ))) - { - if(entity.ignoreExplosion()) + for (LivingEntity entity : this.level().getEntitiesOfClass(LivingEntity.class, new AABB(minX, minY, minZ, maxX, maxY, maxZ))) { + if (entity.ignoreExplosion()) continue; eyes = entity.getEyePosition(1.0F); @@ -102,25 +92,20 @@ public void onDeath() double angle = Math.toDegrees(Math.acos(entity.getViewVector(1.0F).dot(directionGrenade.normalize()))); // Apply effects as determined by their criteria - if(this.calculateAndApplyEffect(ModEffects.DEAFENED.get(), Config.COMMON.stunGrenades.deafen.criteria, entity, grenade, eyes, distance, angle) && Config.COMMON.stunGrenades.deafen.panicMobs.get()) - { + if (this.calculateAndApplyEffect(ModEffects.DEAFENED.get(), Config.COMMON.stunGrenades.deafen.criteria, entity, grenade, eyes, distance, angle) && Config.COMMON.stunGrenades.deafen.panicMobs.get()) { entity.setLastHurtByMob(entity); } - if(this.calculateAndApplyEffect(ModEffects.BLINDED.get(), Config.COMMON.stunGrenades.blind.criteria, entity, grenade, eyes, distance, angle) && Config.COMMON.stunGrenades.blind.blindMobs.get() && entity instanceof Mob) - { + if (this.calculateAndApplyEffect(ModEffects.BLINDED.get(), Config.COMMON.stunGrenades.blind.criteria, entity, grenade, eyes, distance, angle) && Config.COMMON.stunGrenades.blind.blindMobs.get() && entity instanceof Mob) { ((Mob) entity).setTarget(null); } } } - private boolean calculateAndApplyEffect(MobEffect effect, EffectCriteria criteria, LivingEntity entity, Vec3 grenade, Vec3 eyes, double distance, double angle) - { + private boolean calculateAndApplyEffect(MobEffect effect, EffectCriteria criteria, LivingEntity entity, Vec3 grenade, Vec3 eyes, double distance, double angle) { double angleMax = criteria.angleEffect.get() * 0.5; - if(distance <= criteria.radius.get() && angleMax > 0 && angle <= angleMax) - { + if (distance <= criteria.radius.get() && angleMax > 0 && angle <= angleMax) { // Verify that light can pass through all blocks obstructing the entity's line of sight to the grenade - if(effect != ModEffects.BLINDED.get() || !Config.COMMON.stunGrenades.blind.criteria.raytraceOpaqueBlocks.get() || rayTraceOpaqueBlocks(this.level, eyes, grenade, false, false, false) == null) - { + if (effect != ModEffects.BLINDED.get() || !Config.COMMON.stunGrenades.blind.criteria.raytraceOpaqueBlocks.get() || rayTraceOpaqueBlocks(this.level(), eyes, grenade, false, false, false) == null) { // Duration attenuated by distance int durationBlinded = (int) Math.round(criteria.durationMax.get() - (criteria.durationMax.get() - criteria.durationMin.get()) * (distance / criteria.radius.get())); @@ -136,12 +121,9 @@ private boolean calculateAndApplyEffect(MobEffect effect, EffectCriteria criteri } @Nullable - public HitResult rayTraceOpaqueBlocks(Level world, Vec3 start, Vec3 end, boolean stopOnLiquid, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock) - { - if(!Double.isNaN(start.x) && !Double.isNaN(start.y) && !Double.isNaN(start.z)) - { - if(!Double.isNaN(end.x) && !Double.isNaN(end.y) && !Double.isNaN(end.z)) - { + public HitResult rayTraceOpaqueBlocks(Level world, Vec3 start, Vec3 end, boolean stopOnLiquid, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock) { + if (!Double.isNaN(start.x) && !Double.isNaN(start.y) && !Double.isNaN(start.z)) { + if (!Double.isNaN(end.x) && !Double.isNaN(end.y) && !Double.isNaN(end.z)) { int endX = Mth.floor(end.x); int endY = Mth.floor(end.y); int endZ = Mth.floor(end.z); @@ -152,26 +134,21 @@ public HitResult rayTraceOpaqueBlocks(Level world, Vec3 start, Vec3 end, boolean BlockState stateInside = world.getBlockState(pos); // Added light opacity check - if(stateInside.getLightBlock(world, pos) != 0 && (!ignoreBlockWithoutBoundingBox || stateInside.getCollisionShape(world, pos) != Shapes.empty())) - { + if (stateInside.getLightBlock(world, pos) != 0 && (!ignoreBlockWithoutBoundingBox || stateInside.getCollisionShape(world, pos) != Shapes.empty())) { HitResult raytraceresult = world.clip(new ClipContext(start, end, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)); - if(raytraceresult != null) - { + if (raytraceresult != null) { return raytraceresult; } } HitResult raytraceresult2 = null; int limit = 200; - while(limit-- >= 0) - { - if(Double.isNaN(start.x) || Double.isNaN(start.y) || Double.isNaN(start.z)) - { + while (limit-- >= 0) { + if (Double.isNaN(start.x) || Double.isNaN(start.y) || Double.isNaN(start.z)) { return null; } - if(startX == endX && startY == endY && startZ == endZ) - { + if (startX == endX && startY == endY && startZ == endZ) { return returnLastUncollidableBlock ? raytraceresult2 : null; } @@ -182,42 +159,27 @@ public HitResult rayTraceOpaqueBlocks(Level world, Vec3 start, Vec3 end, boolean double d1 = 999; double d2 = 999; - if(endX > startX) - { + if (endX > startX) { d0 = startX + 1; - } - else if(endX < startX) - { + } else if (endX < startX) { d0 = startX; - } - else - { + } else { completedX = false; } - if(endY > startY) - { + if (endY > startY) { d1 = startY + 1; - } - else if(endY < startY) - { + } else if (endY < startY) { d1 = startY; - } - else - { + } else { completedY = false; } - if(endZ > startZ) - { + if (endZ > startZ) { d2 = startZ + 1; - } - else if(endZ < startZ) - { + } else if (endZ < startZ) { d2 = startZ; - } - else - { + } else { completedZ = false; } @@ -228,32 +190,27 @@ else if(endZ < startZ) double d7 = end.y - start.y; double d8 = end.z - start.z; - if(completedX) d3 = (d0 - start.x) / d6; + if (completedX) d3 = (d0 - start.x) / d6; - if(completedY) d4 = (d1 - start.y) / d7; + if (completedY) d4 = (d1 - start.y) / d7; - if(completedZ) d5 = (d2 - start.z) / d8; + if (completedZ) d5 = (d2 - start.z) / d8; - if(d3 == -0) d3 = -1.0E-4D; + if (d3 == -0) d3 = -1.0E-4D; - if(d4 == -0) d4 = -1.0E-4D; + if (d4 == -0) d4 = -1.0E-4D; - if(d5 == -0) d5 = -1.0E-4D; + if (d5 == -0) d5 = -1.0E-4D; Direction direction; - if(d3 < d4 && d3 < d5) - { + if (d3 < d4 && d3 < d5) { direction = endX > startX ? Direction.WEST : Direction.EAST; start = new Vec3(d0, start.y + d7 * d3, start.z + d8 * d3); - } - else if(d4 < d5) - { + } else if (d4 < d5) { direction = endY > startY ? Direction.DOWN : Direction.UP; start = new Vec3(start.x + d6 * d4, d1, start.z + d8 * d4); - } - else - { + } else { direction = endZ > startZ ? Direction.NORTH : Direction.SOUTH; start = new Vec3(start.x + d6 * d5, start.y + d7 * d5, d2); } @@ -265,8 +222,7 @@ else if(d4 < d5) BlockState state = world.getBlockState(pos); // Added light opacity check - if(state.getLightBlock(world, pos) != 0 && (!ignoreBlockWithoutBoundingBox || state.getMaterial() == Material.PORTAL || state.getCollisionShape(world, pos) != Shapes.empty())) - { + if (state.getLightBlock(world, pos) != 0 && (!ignoreBlockWithoutBoundingBox || state.is(Blocks.NETHER_PORTAL) || state.getCollisionShape(world, pos) != Shapes.empty())) { return world.clip(new ClipContext(start, end, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)); } } diff --git a/src/main/java/com/mrcrayfish/guns/init/ModBlocks.java b/src/main/java/com/mrcrayfish/guns/init/ModBlocks.java index 56b9b17ee..87e78d83c 100644 --- a/src/main/java/com/mrcrayfish/guns/init/ModBlocks.java +++ b/src/main/java/com/mrcrayfish/guns/init/ModBlocks.java @@ -5,7 +5,8 @@ import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.material.MapColor; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.RegistryObject; @@ -17,22 +18,18 @@ /** * Author: MrCrayfish */ -public class ModBlocks -{ +public class ModBlocks { public static final DeferredRegister REGISTER = DeferredRegister.create(ForgeRegistries.BLOCKS, Reference.MOD_ID); - public static final RegistryObject WORKBENCH = register("workbench", () -> new WorkbenchBlock(Block.Properties.of(Material.METAL).strength(1.5F))); + public static final RegistryObject WORKBENCH = register("workbench", () -> new WorkbenchBlock(Block.Properties.of().strength(1.5F).sound(SoundType.METAL).mapColor(MapColor.METAL))); - private static RegistryObject register(String id, Supplier blockSupplier) - { + private static RegistryObject register(String id, Supplier blockSupplier) { return register(id, blockSupplier, block1 -> new BlockItem(block1, new Item.Properties())); } - private static RegistryObject register(String id, Supplier blockSupplier, @Nullable Function supplier) - { + private static RegistryObject register(String id, Supplier blockSupplier, @Nullable Function supplier) { RegistryObject registryObject = REGISTER.register(id, blockSupplier); - if(supplier != null) - { + if (supplier != null) { ModItems.REGISTER.register(id, () -> supplier.apply(registryObject.get())); } return registryObject; diff --git a/src/main/java/com/mrcrayfish/guns/init/ModContainers.java b/src/main/java/com/mrcrayfish/guns/init/ModContainers.java index bf10becca..f18b9f266 100644 --- a/src/main/java/com/mrcrayfish/guns/init/ModContainers.java +++ b/src/main/java/com/mrcrayfish/guns/init/ModContainers.java @@ -20,7 +20,7 @@ public class ModContainers public static final DeferredRegister> REGISTER = DeferredRegister.create(ForgeRegistries.MENU_TYPES, Reference.MOD_ID); public static final RegistryObject> WORKBENCH = register("workbench", (IContainerFactory) (windowId, playerInventory, data) -> { - WorkbenchBlockEntity workstation = (WorkbenchBlockEntity) playerInventory.player.level.getBlockEntity(data.readBlockPos()); + WorkbenchBlockEntity workstation = (WorkbenchBlockEntity) playerInventory.player.level().getBlockEntity(data.readBlockPos()); return new WorkbenchContainer(windowId, playerInventory, workstation); }); diff --git a/src/main/java/com/mrcrayfish/guns/item/GrenadeItem.java b/src/main/java/com/mrcrayfish/guns/item/GrenadeItem.java index 31b81c704..07b9e3242 100644 --- a/src/main/java/com/mrcrayfish/guns/item/GrenadeItem.java +++ b/src/main/java/com/mrcrayfish/guns/item/GrenadeItem.java @@ -37,16 +37,16 @@ public int getUseDuration(ItemStack stack) { return this.maxCookTime; } - + @Override - public void onUsingTick(ItemStack stack, LivingEntity player, int count) + public void onUseTick(Level level, LivingEntity player, ItemStack stack, int count) { if(!this.canCook()) return; int duration = this.getUseDuration(stack) - count; if(duration == 10) - player.level.playLocalSound(player.getX(), player.getY(), player.getZ(), ModSounds.ITEM_GRENADE_PIN.get(), SoundSource.PLAYERS, 1.0F, 1.0F, false); + player.level().playLocalSound(player.getX(), player.getY(), player.getZ(), ModSounds.ITEM_GRENADE_PIN.get(), SoundSource.PLAYERS, 1.0F, 1.0F, false); } @Override diff --git a/src/main/java/com/mrcrayfish/guns/jei/WorkbenchCategory.java b/src/main/java/com/mrcrayfish/guns/jei/WorkbenchCategory.java index 403422d17..d6f8f3b4a 100644 --- a/src/main/java/com/mrcrayfish/guns/jei/WorkbenchCategory.java +++ b/src/main/java/com/mrcrayfish/guns/jei/WorkbenchCategory.java @@ -21,9 +21,8 @@ import mezz.jei.api.recipe.category.IRecipeCategory; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.block.model.ItemTransforms; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.resources.language.I18n; import net.minecraft.client.resources.model.BakedModel; @@ -36,14 +35,14 @@ import net.minecraft.world.item.ItemStack; import net.minecraftforge.registries.ForgeRegistries; +import java.awt.*; import java.util.stream.Collectors; import java.util.stream.Stream; /** * Author: MrCrayfish */ -public class WorkbenchCategory implements IRecipeCategory -{ +public class WorkbenchCategory implements IRecipeCategory { public static final ResourceLocation ID = new ResourceLocation(Reference.MOD_ID, "workbench"); public static final ResourceLocation BACKGROUND = new ResourceLocation(Reference.MOD_ID, "textures/gui/workbench.png"); public static final String TITLE_KEY = Reference.MOD_ID + ".category.workbench.title"; @@ -57,8 +56,7 @@ public class WorkbenchCategory implements IRecipeCategory private final Component title; private final Item[] dyes; - public WorkbenchCategory(IGuiHelper helper) - { + public WorkbenchCategory(IGuiHelper helper) { this.background = helper.createBlankDrawable(162, 124); this.window = helper.createDrawable(BACKGROUND, 7, 15, 162, 72); this.inventory = helper.createDrawable(BACKGROUND, 7, 101, 162, 36); @@ -69,66 +67,57 @@ public WorkbenchCategory(IGuiHelper helper) } @Override - public RecipeType getRecipeType() - { + public RecipeType getRecipeType() { return GunModPlugin.WORKBENCH; } @Override - public Component getTitle() - { + public Component getTitle() { return this.title; } @Override - public IDrawable getBackground() - { + public IDrawable getBackground() { return this.background; } @Override - public IDrawable getIcon() - { + public IDrawable getIcon() { return this.icon; } @Override - public void setRecipe(IRecipeLayoutBuilder builder, WorkbenchRecipe recipe, IFocusGroup focuses) - { + public void setRecipe(IRecipeLayoutBuilder builder, WorkbenchRecipe recipe, IFocusGroup focuses) { ItemStack output = recipe.getItem(); - if(IColored.isDyeable(output)) - { + if (IColored.isDyeable(output)) { builder.addSlot(RecipeIngredientRole.INPUT, 141, 52).addItemStacks(Stream.of(this.dyes).map(ItemStack::new).collect(Collectors.toList())); } - for(int i = 0; i < recipe.getMaterials().size(); i++) - { + for (int i = 0; i < recipe.getMaterials().size(); i++) { builder.addSlot(RecipeIngredientRole.INPUT, (i % 8) * 18 + 1, 88 + (i / 8) * 18).addIngredients(recipe.getMaterials().get(i)); } builder.addInvisibleIngredients(RecipeIngredientRole.OUTPUT).addItemStack(output); } - + @Override - public void draw(WorkbenchRecipe recipe, IRecipeSlotsView recipeSlotsView, PoseStack poseStack, double mouseX, double mouseY) - { - this.window.draw(poseStack, 0, 0); - this.inventory.draw(poseStack, 0, this.window.getHeight() + 2 + 11 + 2); - this.dyeSlot.draw(poseStack, 140, 51); - - Minecraft.getInstance().font.draw(poseStack, I18n.get(MATERIALS_KEY), 0, 78, 0x7E7E7E); + public void draw(WorkbenchRecipe recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics graphics, double mouseX, double mouseY) { + this.window.draw(graphics, 0, 0); + this.inventory.draw(graphics, 0, this.window.getHeight() + 2 + 11 + 2); + this.dyeSlot.draw(graphics, 140, 51); + + graphics.drawString(Minecraft.getInstance().font, I18n.get(MATERIALS_KEY), 0, 78, Color.WHITE.getRGB()); ItemStack output = recipe.getItem(); MutableComponent displayName = output.getHoverName().copy(); - if(output.getCount() > 1) - { + if (output.getCount() > 1) { displayName.append(Component.literal(" x " + output.getCount()).withStyle(ChatFormatting.GOLD, ChatFormatting.BOLD)); } int titleX = this.window.getWidth() / 2; - GuiComponent.drawCenteredString(poseStack, Minecraft.getInstance().font, displayName, titleX, 5, 0xFFFFFFFF); + graphics.drawCenteredString(Minecraft.getInstance().font, displayName, titleX, 5, Color.WHITE.getRGB()); PoseStack stack = RenderSystem.getModelViewStack(); stack.pushPose(); { - stack.mulPoseMatrix(poseStack.last().pose()); + stack.mulPoseMatrix(graphics.pose().last().pose()); stack.translate(81, 40, 0); stack.scale(40F, 40F, 40F); stack.mulPose(Axis.XP.rotationDegrees(-5F)); diff --git a/src/main/java/com/mrcrayfish/guns/mixin/client/GameRendererMixin.java b/src/main/java/com/mrcrayfish/guns/mixin/client/GameRendererMixin.java index 53720b4be..522395311 100644 --- a/src/main/java/com/mrcrayfish/guns/mixin/client/GameRendererMixin.java +++ b/src/main/java/com/mrcrayfish/guns/mixin/client/GameRendererMixin.java @@ -1,11 +1,10 @@ package com.mrcrayfish.guns.mixin.client; import com.mojang.blaze3d.platform.Window; -import com.mojang.blaze3d.vertex.PoseStack; import com.mrcrayfish.guns.Config; import com.mrcrayfish.guns.init.ModEffects; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.entity.player.Player; @@ -15,26 +14,22 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(GameRenderer.class) -public class GameRendererMixin -{ +public class GameRendererMixin { @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V", ordinal = 0, shift = At.Shift.AFTER)) - public void updateCameraAndRender(float partialTicks, long nanoTime, boolean renderWorldIn, CallbackInfo ci) - { + public void updateCameraAndRender(float partialTicks, long nanoTime, boolean renderWorldIn, CallbackInfo ci) { Minecraft minecraft = Minecraft.getInstance(); Player player = minecraft.player; - if (player == null) - { + if (player == null) { return; } MobEffectInstance effect = player.getEffect(ModEffects.BLINDED.get()); - if (effect != null) - { + if (effect != null) { // Render white screen-filling overlay at full alpha effect when duration is above threshold // When below threshold, fade to full transparency as duration approaches 0 float percent = Math.min((effect.getDuration() / (float) Config.SERVER.alphaFadeThreshold.get()), 1); - Window window = Minecraft.getInstance().getWindow(); - GuiComponent.fill(new PoseStack(), 0, 0, window.getScreenWidth(), window.getScreenHeight(), ((int) (percent * Config.SERVER.alphaOverlay.get() + 0.5) << 24) | 16777215); + Window window = minecraft.getWindow(); + new GuiGraphics(minecraft, minecraft.renderBuffers().bufferSource()).fill(0, 0, window.getScreenWidth(), window.getScreenHeight(), ((int) (percent * Config.SERVER.alphaOverlay.get() + 0.5) << 24) | 16777215); } } } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index e57590c68..e9ffebc95 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -4,7 +4,7 @@ license="GPL3" [[mods]] modId="cgm" -version="1.3.7" +version="1.3.8" displayName="MrCrayfish's Gun Mod" updateJSONURL="https://raw.githubusercontent.com/MrCrayfish/ModUpdates/master/cgm/update.json" displayURL="https://mrcrayfish.com/" @@ -15,13 +15,13 @@ description="MrCrayfish's Gun Mod adds in simple and straight forward weapons in [[dependencies.cgm]] modId="forge" mandatory=true - versionRange="[44.1.0,)" + versionRange="[44.1.0,47.2.8]" ordering="NONE" side="BOTH" [[dependencies.cgm]] modId="minecraft" mandatory=true - versionRange="[1.19.4,1.20)" + versionRange="[1.19.4,1.20.1]" ordering="NONE" side="BOTH" [[dependencies.cgm]]