From 2b5b87d3da5127700cb37c23493b6d7f359081e0 Mon Sep 17 00:00:00 2001 From: Purplicious_Cow Date: Sun, 20 Aug 2017 23:32:49 +0200 Subject: [PATCH 1/5] Flicker fix (1.11.2 only) --- .../client/event/RenderEntityEvents.java | 36 ++----------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/src/main/java/tschipp/carryon/client/event/RenderEntityEvents.java b/src/main/java/tschipp/carryon/client/event/RenderEntityEvents.java index c3b5a68..9863cbb 100644 --- a/src/main/java/tschipp/carryon/client/event/RenderEntityEvents.java +++ b/src/main/java/tschipp/carryon/client/event/RenderEntityEvents.java @@ -158,7 +158,7 @@ public class RenderEntityEvents if (perspective == 0 && Minecraft.getMinecraft().inGameHasFocus) { Minecraft.getMinecraft().getRenderManager().setRenderShadow(false); - Minecraft.getMinecraft().getRenderManager().renderEntityStatic(entity, 0.0f, false); + Minecraft.getMinecraft().getRenderManager().renderEntityStatic(entity, 1.0f, false); Minecraft.getMinecraft().getRenderManager().setRenderShadow(true); } @@ -229,7 +229,7 @@ public class RenderEntityEvents GlStateManager.translate(0, -0.3, 0); Minecraft.getMinecraft().getRenderManager().setRenderShadow(false); - Minecraft.getMinecraft().getRenderManager().renderEntityStatic(entity, 0.0f, false); + Minecraft.getMinecraft().getRenderManager().renderEntityStatic(entity, 1.0f, false); Minecraft.getMinecraft().getRenderManager().setRenderShadow(true); GlStateManager.scale(1, 1, 1); @@ -240,37 +240,5 @@ public class RenderEntityEvents } - public void renderEntityStaticCO(Entity entityIn, float partialTicks, boolean p_188388_3_) - { - if (entityIn.ticksExisted == 0) - { - entityIn.lastTickPosX = entityIn.posX; - entityIn.lastTickPosY = entityIn.posY; - entityIn.lastTickPosZ = entityIn.posZ; - } - - double d0 = entityIn.lastTickPosX + (entityIn.posX - entityIn.lastTickPosX) * (double)partialTicks; - double d1 = entityIn.lastTickPosY + (entityIn.posY - entityIn.lastTickPosY) * (double)partialTicks; - double d2 = entityIn.lastTickPosZ + (entityIn.posZ - entityIn.lastTickPosZ) * (double)partialTicks; - float f = entityIn.prevRotationYaw + (entityIn.rotationYaw - entityIn.prevRotationYaw) * partialTicks; - - int i = 0; - if (!Minecraft.getMinecraft().world.isDaytime()) { - i = entityIn.getBrightnessForRender(partialTicks); - } else { - i = 50000; - } - if (entityIn.isBurning()) - { - i = 15728880; - } - - int j = i % 65536; - int k = i / 65536; - OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)j, (float)k); - GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - RenderManager manager = Minecraft.getMinecraft().getRenderManager(); - manager.doRenderEntity(entityIn, d0, d1, d2, f, partialTicks, p_188388_3_); - } } From 24fdee0125ffacf77c0eac67f5d475a1173101db Mon Sep 17 00:00:00 2001 From: Tschipp Date: Mon, 21 Aug 2017 22:25:35 +0200 Subject: [PATCH 2/5] Fixed ItemTile and updated Update JSON --- src/main/java/tschipp/carryon/CarryOn.java | 2 +- src/main/java/tschipp/carryon/common/item/ItemTile.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/tschipp/carryon/CarryOn.java b/src/main/java/tschipp/carryon/CarryOn.java index ff43e7f..95bc076 100644 --- a/src/main/java/tschipp/carryon/CarryOn.java +++ b/src/main/java/tschipp/carryon/CarryOn.java @@ -28,7 +28,7 @@ public class CarryOn { public static final String MODID = "carryon"; public static final String VERSION = "1.2"; public static final String NAME = "Carry On"; - public static final String UPDATE_JSON = "https://gist.githubusercontent.com/Tschipp/dccadee7c90d7a34e6e76a35d9d6fa2e/raw/bf7fb60d5e59f73eee65b271d5c01585e26a0352/update.json"; + public static final String UPDATE_JSON = "https://gist.githubusercontent.com/Tschipp/dccadee7c90d7a34e6e76a35d9d6fa2e/raw/"; public static final Logger LOGGER = LogManager.getFormatterLogger("CarryOn"); //public static SimpleNetworkWrapper network; diff --git a/src/main/java/tschipp/carryon/common/item/ItemTile.java b/src/main/java/tschipp/carryon/common/item/ItemTile.java index b8c1552..088bcc1 100644 --- a/src/main/java/tschipp/carryon/common/item/ItemTile.java +++ b/src/main/java/tschipp/carryon/common/item/ItemTile.java @@ -91,7 +91,7 @@ public class ItemTile extends Item pos2 = pos.offset(facing); } - if (world.getBlockState(pos2).getBlock().isReplaceable(world, pos2)) + if (world.getBlockState(pos2).getBlock().isReplaceable(world, pos2) && containedblock != null) { boolean canPlace = containedblock.canPlaceBlockAt(world, pos2); @@ -227,8 +227,8 @@ public class ItemTile extends Item if (stack.hasTagCompound()) { NBTTagCompound tag = stack.getTagCompound(); - String name = tag.getString("block"); - return Block.getBlockFromName(name); + int id = tag.getInteger("stateid"); + return Block.getStateById(id).getBlock(); } return Blocks.AIR; } From bb157fcb6a1c6b82fe11687a184f07f0313ba08a Mon Sep 17 00:00:00 2001 From: Purplicious_Cow Date: Sun, 27 Aug 2017 21:28:03 +0200 Subject: [PATCH 3/5] Renderrific Updated arm render to only show remove Carry On arms. Fixed dimness when carrying entities at night. Added config. 1.11.2 only. --- .../client/event/RenderEntityEvents.java | 14 +++-- .../carryon/client/event/RenderEvents.java | 52 ++++++++++++------- .../carryon/common/config/Configs.java | 3 ++ 3 files changed, 47 insertions(+), 22 deletions(-) diff --git a/src/main/java/tschipp/carryon/client/event/RenderEntityEvents.java b/src/main/java/tschipp/carryon/client/event/RenderEntityEvents.java index 9863cbb..4c4aae7 100644 --- a/src/main/java/tschipp/carryon/client/event/RenderEntityEvents.java +++ b/src/main/java/tschipp/carryon/client/event/RenderEntityEvents.java @@ -13,6 +13,7 @@ import net.minecraft.client.model.ModelPlayer; import net.minecraft.client.model.ModelRenderer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.entity.RenderPlayer; import net.minecraft.client.resources.DefaultPlayerSkin; @@ -155,10 +156,11 @@ public class RenderEntityEvents GlStateManager.enableAlpha(); - if (perspective == 0 && Minecraft.getMinecraft().inGameHasFocus) + if (perspective == 0) { + RenderHelper.enableStandardItemLighting(); Minecraft.getMinecraft().getRenderManager().setRenderShadow(false); - Minecraft.getMinecraft().getRenderManager().renderEntityStatic(entity, 1.0f, false); + Minecraft.getMinecraft().getRenderManager().renderEntityStatic(entity, 0.0f, false); Minecraft.getMinecraft().getRenderManager().setRenderShadow(true); } @@ -167,6 +169,12 @@ public class RenderEntityEvents GlStateManager.scale(1, 1, 1); GlStateManager.popMatrix(); + + RenderHelper.disableStandardItemLighting(); + GlStateManager.disableRescaleNormal(); + GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit); + GlStateManager.disableTexture2D(); + GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit); if (perspective == 0) event.setCanceled(true); @@ -229,7 +237,7 @@ public class RenderEntityEvents GlStateManager.translate(0, -0.3, 0); Minecraft.getMinecraft().getRenderManager().setRenderShadow(false); - Minecraft.getMinecraft().getRenderManager().renderEntityStatic(entity, 1.0f, false); + Minecraft.getMinecraft().getRenderManager().renderEntityStatic(entity, 0.0f, false); Minecraft.getMinecraft().getRenderManager().setRenderShadow(true); GlStateManager.scale(1, 1, 1); diff --git a/src/main/java/tschipp/carryon/client/event/RenderEvents.java b/src/main/java/tschipp/carryon/client/event/RenderEvents.java index 930237a..8d125cc 100644 --- a/src/main/java/tschipp/carryon/client/event/RenderEvents.java +++ b/src/main/java/tschipp/carryon/client/event/RenderEvents.java @@ -275,27 +275,35 @@ public class RenderEvents @SubscribeEvent public void onPlayerRenderPre(RenderPlayerEvent.Pre event) { - - if (!Loader.isModLoaded("mobends")) { + + if (!Loader.isModLoaded("mobends") && CarryOnConfig.settings.renderArms) { EntityPlayer player = event.getEntityPlayer(); AbstractClientPlayer aplayer = (AbstractClientPlayer) player; ItemStack stack = player.getHeldItemMainhand(); ModelPlayer model = event.getRenderer().getMainModel(); EntityPlayerSP clientPlayer = Minecraft.getMinecraft().player; - + ResourceLocation skinLoc = DefaultPlayerSkin.getDefaultSkin(player.getPersistentID()); ModelRenderer fakeLeftArm = new ModelRenderer(model, 32, 48); ModelRenderer fakeRightArm = new ModelRenderer(model, 40, 16); - + player.setArrowCountInEntity(0); //TODO Temporary Fix - + if (!stack.isEmpty() && (stack.getItem() == RegistrationHandler.itemTile && ItemTile.hasTileData(stack)) || (stack.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack))) { - - if (model.bipedBody.childModels != null && !model.bipedBody.childModels.isEmpty()) { - model.bipedBody.childModels.clear(); + if (model.bipedBody.childModels != null && !model.bipedBody.childModels.isEmpty()) + { + + for (int k = 0; k < model.bipedBody.childModels.size(); k++) { + float chkRot = model.bipedBody.childModels.get(k).rotateAngleX; + if (chkRot == -0.9001F || chkRot == -1.2001F || chkRot == -1.4001F || chkRot == -1.7001F) { + model.bipedBody.childModels.remove(k); + k = k -1; + } + } + } Item item = stack.getItem(); @@ -305,6 +313,7 @@ public class RenderEvents Minecraft.getMinecraft().getTextureManager().bindTexture(skinLoc); float rotation = -player.renderYawOffset; + if (aplayer.getSkinType().equals("default")) { fakeLeftArm.addBox(model.bipedLeftArm.offsetX + 4.2F, model.bipedLeftArm.offsetY, model.bipedLeftArm.offsetZ, 4, 12, 4, .08F); @@ -327,26 +336,26 @@ public class RenderEvents { if (!player.isSneaking()) { - fakeRightArm.rotateAngleX = -.9F; - fakeLeftArm.rotateAngleX = -.9F; + fakeRightArm.rotateAngleX = -.9001F; + fakeLeftArm.rotateAngleX = -.9001F; } else { - fakeRightArm.rotateAngleX = -1.4F; - fakeLeftArm.rotateAngleX = -1.4F; + fakeRightArm.rotateAngleX = -1.4001F; + fakeLeftArm.rotateAngleX = -1.4001F; } } else { if (!player.isSneaking()) { - fakeRightArm.rotateAngleX = -1.2F; - fakeLeftArm.rotateAngleX = -1.2F; + fakeRightArm.rotateAngleX = -1.2001F; + fakeLeftArm.rotateAngleX = -1.2001F; } else { - fakeRightArm.rotateAngleX = -1.7F; - fakeLeftArm.rotateAngleX = -1.7F; + fakeRightArm.rotateAngleX = -1.7001F; + fakeLeftArm.rotateAngleX = -1.7001F; } fakeRightArm.rotateAngleY = -0.15f; @@ -361,10 +370,16 @@ public class RenderEvents { model.bipedLeftArm.isHidden = false; model.bipedRightArm.isHidden = false; - + if (model.bipedBody.childModels != null && !model.bipedBody.childModels.isEmpty()) { - model.bipedBody.childModels.clear(); + for (int k = 0; k < model.bipedBody.childModels.size(); k++) { + float chkRot = model.bipedBody.childModels.get(k).rotateAngleX; + if (chkRot == - 0.9001F || chkRot == -1.2001F || chkRot == -1.4001F || chkRot == -1.7001F) { + model.bipedBody.childModels.remove(k); + k = k - 1; + } + } } } @@ -374,7 +389,6 @@ public class RenderEvents model.bipedRightArm.isHidden = false; } } - } diff --git a/src/main/java/tschipp/carryon/common/config/Configs.java b/src/main/java/tschipp/carryon/common/config/Configs.java index 7060ce1..bbe0f8a 100644 --- a/src/main/java/tschipp/carryon/common/config/Configs.java +++ b/src/main/java/tschipp/carryon/common/config/Configs.java @@ -36,6 +36,9 @@ public class Configs { @Comment("Larger Entities slow down the player more") public boolean heavyEntities = true; + + @Comment("Arms should render on sides when carrying") + public boolean renderArms = true; } public static class Blacklist From 7509e52c8c8424bbe40382d8c8a9e3a2be96274a Mon Sep 17 00:00:00 2001 From: Tschipp Date: Sun, 27 Aug 2017 21:30:24 +0200 Subject: [PATCH 4/5] Added Keybind for carrying --- src/main/java/tschipp/carryon/CarryOn.java | 3 +- .../tschipp/carryon/client/ClientProxy.java | 2 + .../client/keybinds/CarryOnKeybinds.java | 44 +++++++++++++++++++ .../tschipp/carryon/common/CommonProxy.java | 8 ++++ .../carryon/common/config/Configs.java | 12 ++++- .../common/event/ItemEntityEvents.java | 34 +++++++++++++- .../carryon/common/event/ItemEvents.java | 4 +- .../carryon/common/handler/PickupHandler.java | 2 + .../carryon/common/item/ItemEntity.java | 2 +- .../tschipp/carryon/common/item/ItemTile.java | 2 +- .../network/server/SyncKeybindPacket.java | 35 +++++++++++++++ .../server/SyncKeybindPacketHandler.java | 34 ++++++++++++++ .../resources/assets/carryon/lang/en_US.lang | 3 ++ 13 files changed, 178 insertions(+), 7 deletions(-) create mode 100644 src/main/java/tschipp/carryon/client/keybinds/CarryOnKeybinds.java create mode 100644 src/main/java/tschipp/carryon/network/server/SyncKeybindPacket.java create mode 100644 src/main/java/tschipp/carryon/network/server/SyncKeybindPacketHandler.java diff --git a/src/main/java/tschipp/carryon/CarryOn.java b/src/main/java/tschipp/carryon/CarryOn.java index 95bc076..f60d2d6 100644 --- a/src/main/java/tschipp/carryon/CarryOn.java +++ b/src/main/java/tschipp/carryon/CarryOn.java @@ -12,6 +12,7 @@ import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; import tschipp.carryon.common.CommonProxy; @EventBusSubscriber @@ -31,7 +32,7 @@ public class CarryOn { public static final String UPDATE_JSON = "https://gist.githubusercontent.com/Tschipp/dccadee7c90d7a34e6e76a35d9d6fa2e/raw/"; public static final Logger LOGGER = LogManager.getFormatterLogger("CarryOn"); - //public static SimpleNetworkWrapper network; + public static SimpleNetworkWrapper network; @EventHandler public void preInit(FMLPreInitializationEvent event) { diff --git a/src/main/java/tschipp/carryon/client/ClientProxy.java b/src/main/java/tschipp/carryon/client/ClientProxy.java index 5986f60..f42de29 100644 --- a/src/main/java/tschipp/carryon/client/ClientProxy.java +++ b/src/main/java/tschipp/carryon/client/ClientProxy.java @@ -3,6 +3,7 @@ package tschipp.carryon.client; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import tschipp.carryon.client.keybinds.CarryOnKeybinds; import tschipp.carryon.common.CommonProxy; import tschipp.carryon.common.handler.RegistrationHandler; @@ -19,6 +20,7 @@ public class ClientProxy extends CommonProxy { @Override public void init(FMLInitializationEvent event) { + CarryOnKeybinds.init(); super.init(event); } diff --git a/src/main/java/tschipp/carryon/client/keybinds/CarryOnKeybinds.java b/src/main/java/tschipp/carryon/client/keybinds/CarryOnKeybinds.java new file mode 100644 index 0000000..25eaad2 --- /dev/null +++ b/src/main/java/tschipp/carryon/client/keybinds/CarryOnKeybinds.java @@ -0,0 +1,44 @@ +package tschipp.carryon.client.keybinds; + +import org.lwjgl.input.Keyboard; + +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fml.client.registry.ClientRegistry; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class CarryOnKeybinds +{ + + public static final String KEYBIND_KEY = "carryOnKeyPressed"; + public static KeyBinding carryKey; + + @SideOnly(Side.CLIENT) + public static void init() + { + carryKey = new KeyBinding("key.carry.desc", Keyboard.KEY_LSHIFT, "key.carry.category"); + + ClientRegistry.registerKeyBinding(carryKey); + } + + public static boolean isKeyPressed(EntityPlayer player) + { + NBTTagCompound tag = player.getEntityData(); + if(tag != null && tag.hasKey(KEYBIND_KEY)) + { + return tag.getBoolean(KEYBIND_KEY); + } + return false; + } + + public static void setKeyPressed(EntityPlayer player, boolean pressed) + { + NBTTagCompound tag = player.getEntityData(); + tag.setBoolean(KEYBIND_KEY, pressed); + } + + + +} diff --git a/src/main/java/tschipp/carryon/common/CommonProxy.java b/src/main/java/tschipp/carryon/common/CommonProxy.java index 3edebe9..29538cd 100644 --- a/src/main/java/tschipp/carryon/common/CommonProxy.java +++ b/src/main/java/tschipp/carryon/common/CommonProxy.java @@ -4,8 +4,12 @@ import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.network.NetworkRegistry; +import net.minecraftforge.fml.relauncher.Side; import tschipp.carryon.CarryOn; import tschipp.carryon.common.handler.RegistrationHandler; +import tschipp.carryon.network.server.SyncKeybindPacket; +import tschipp.carryon.network.server.SyncKeybindPacketHandler; public class CommonProxy { @@ -13,6 +17,10 @@ public class CommonProxy @EventHandler public void preInit(FMLPreInitializationEvent event) { + CarryOn.network = NetworkRegistry.INSTANCE.newSimpleChannel("CarryOn"); + + CarryOn.network.registerMessage(SyncKeybindPacketHandler.class, SyncKeybindPacket.class, 0, Side.SERVER); + RegistrationHandler.regItems(); RegistrationHandler.regCommonEvents(); } diff --git a/src/main/java/tschipp/carryon/common/config/Configs.java b/src/main/java/tschipp/carryon/common/config/Configs.java index 7060ce1..2987bb1 100644 --- a/src/main/java/tschipp/carryon/common/config/Configs.java +++ b/src/main/java/tschipp/carryon/common/config/Configs.java @@ -36,6 +36,12 @@ public class Configs { @Comment("Larger Entities slow down the player more") public boolean heavyEntities = true; + + @Comment("Slowness multiplier for blocks") + public double blockSlownessMultiplier = 1.0; + + @Comment("Slowness multiplier for entities") + public double entitySlownessMultiplier = 1.0; } public static class Blacklist @@ -62,6 +68,8 @@ public class Configs { "bigreactors:*", "forestry:*", "tconstruct:*", + "refinedstorage:*", + "rustic:*", "immersiveengineering:*", "embers:block_furnace", "embers:ember_bore", @@ -87,7 +95,8 @@ public class Configs { "minecraft:ender_dragon", "minecraft:ghast", "minecraft:shulker", - "animania:textures/entity/pigs/hamster_tarou.png" + "animania:textures/entity/pigs/hamster_tarou.png", + "mynko:*" }; } @@ -109,6 +118,7 @@ public class Configs { "minecraft:tallgrass;2->(item)minecraft:tallgrass;2", "minecraft:flower_pot->(block)minecraft:flower_pot", "minecraft:leaves2->(item)minecraft:leaves2", + "minecraft:reeds->(block)minecraft:reeds", "quark:custom_chest{type:\"spruce\"}->quark:custom_chest;0", "quark:custom_chest{type:\"birch\"}->quark:custom_chest;1", "quark:custom_chest{type:\"jungle\"}->quark:custom_chest;2", diff --git a/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java b/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java index f895922..e9f24f5 100644 --- a/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java +++ b/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java @@ -1,19 +1,24 @@ package tschipp.carryon.common.event; +import net.minecraft.block.material.Material; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.event.entity.EntityJoinWorldEvent; +import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.fml.common.eventhandler.Event.Result; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import tschipp.carryon.client.keybinds.CarryOnKeybinds; import tschipp.carryon.common.handler.PickupHandler; import tschipp.carryon.common.handler.RegistrationHandler; import tschipp.carryon.common.item.ItemEntity; @@ -56,7 +61,7 @@ public class ItemEntityEvents } } - @SubscribeEvent(priority = EventPriority.NORMAL) + @SubscribeEvent(priority = EventPriority.HIGH) public void onEntityRightClick(PlayerInteractEvent.EntityInteract event) { EntityPlayer player = event.getEntityPlayer(); @@ -69,7 +74,7 @@ public class ItemEntityEvents Entity entity = event.getTarget(); BlockPos pos = entity.getPosition(); - if (main.isEmpty() && off.isEmpty() && player.isSneaking()) + if (main.isEmpty() && off.isEmpty() && CarryOnKeybinds.isKeyPressed(player)) { ItemStack stack = new ItemStack(RegistrationHandler.itemEntity); @@ -88,4 +93,29 @@ public class ItemEntityEvents } + @SubscribeEvent + public void onLivingUpdate(LivingUpdateEvent event) + { + EntityLivingBase entity = event.getEntityLiving(); + World world = entity.world; + ItemStack main = entity.getHeldItemMainhand(); + if (!main.isEmpty() && main.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(main)) + { + BlockPos pos = entity.getPosition(); + BlockPos below = pos.offset(EnumFacing.DOWN); + + if (world.getBlockState(pos).getMaterial() == Material.WATER || world.getBlockState(below).getMaterial() == Material.WATER) + { + Entity contained = ItemEntity.getEntity(main, world); + if (contained != null) + { + float height = contained.height; + float width = contained.width; + + entity.addVelocity(0, -0.01 * height * width, 0); + } + } + } + } + } diff --git a/src/main/java/tschipp/carryon/common/event/ItemEvents.java b/src/main/java/tschipp/carryon/common/event/ItemEvents.java index db1c562..7ff4c25 100644 --- a/src/main/java/tschipp/carryon/common/event/ItemEvents.java +++ b/src/main/java/tschipp/carryon/common/event/ItemEvents.java @@ -2,6 +2,7 @@ package tschipp.carryon.common.event; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; @@ -19,6 +20,7 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.fml.common.eventhandler.Event.Result; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import tschipp.carryon.client.keybinds.CarryOnKeybinds; import tschipp.carryon.common.config.CarryOnConfig; import tschipp.carryon.common.handler.ForbiddenTileHandler; import tschipp.carryon.common.handler.PickupHandler; @@ -92,7 +94,7 @@ public class ItemEvents Block block = world.getBlockState(pos).getBlock(); IBlockState state = world.getBlockState(pos); - if (main.isEmpty() && off.isEmpty() && player.isSneaking() && !ForbiddenTileHandler.isForbidden(block)) + if (main.isEmpty() && off.isEmpty() && CarryOnKeybinds.isKeyPressed(player) && !ForbiddenTileHandler.isForbidden(block)) { ItemStack stack = new ItemStack(RegistrationHandler.itemTile); diff --git a/src/main/java/tschipp/carryon/common/handler/PickupHandler.java b/src/main/java/tschipp/carryon/common/handler/PickupHandler.java index 10bef35..4908e25 100644 --- a/src/main/java/tschipp/carryon/common/handler/PickupHandler.java +++ b/src/main/java/tschipp/carryon/common/handler/PickupHandler.java @@ -11,6 +11,7 @@ import net.darkhax.gamestages.capabilities.PlayerDataHandler; import net.darkhax.gamestages.capabilities.PlayerDataHandler.IStageData; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.EnumCreatureType; import net.minecraft.entity.passive.EntityTameable; @@ -35,6 +36,7 @@ public class PickupHandler player.closeScreen(); + if ((block.getBlockHardness(state, world, pos) != -1 || player.isCreative())) { double distance = pos.distanceSqToCenter(player.posX, player.posY + 0.5, player.posZ); diff --git a/src/main/java/tschipp/carryon/common/item/ItemEntity.java b/src/main/java/tschipp/carryon/common/item/ItemEntity.java index 43dbb79..55f1f9e 100644 --- a/src/main/java/tschipp/carryon/common/item/ItemEntity.java +++ b/src/main/java/tschipp/carryon/common/item/ItemEntity.java @@ -212,6 +212,6 @@ public class ItemEntity extends Item if (!CarryOnConfig.settings.heavyEntities) i = 1; - return i; + return (int) (i * CarryOnConfig.settings.entitySlownessMultiplier); } } diff --git a/src/main/java/tschipp/carryon/common/item/ItemTile.java b/src/main/java/tschipp/carryon/common/item/ItemTile.java index 088bcc1..fe92a4f 100644 --- a/src/main/java/tschipp/carryon/common/item/ItemTile.java +++ b/src/main/java/tschipp/carryon/common/item/ItemTile.java @@ -295,6 +295,6 @@ public class ItemTile extends Item if (!CarryOnConfig.settings.heavyTiles) i = 1; - return i; + return (int) (i * CarryOnConfig.settings.blockSlownessMultiplier); } } diff --git a/src/main/java/tschipp/carryon/network/server/SyncKeybindPacket.java b/src/main/java/tschipp/carryon/network/server/SyncKeybindPacket.java new file mode 100644 index 0000000..3dbca52 --- /dev/null +++ b/src/main/java/tschipp/carryon/network/server/SyncKeybindPacket.java @@ -0,0 +1,35 @@ +package tschipp.carryon.network.server; + +import io.netty.buffer.ByteBuf; +import net.minecraftforge.fml.common.network.ByteBufUtils; +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; + +public class SyncKeybindPacket implements IMessage +{ + + private int p; + public boolean pressed; + + public SyncKeybindPacket() + { + } + + public SyncKeybindPacket(boolean pressed) + { + this.p = pressed ? 1 : 0; + } + + @Override + public void fromBytes(ByteBuf buf) + { + this.p = ByteBufUtils.readVarInt(buf, 4); + this.pressed = p == 1 ? true : false; + } + + @Override + public void toBytes(ByteBuf buf) + { + ByteBufUtils.writeVarInt(buf, p, 4); + } + +} diff --git a/src/main/java/tschipp/carryon/network/server/SyncKeybindPacketHandler.java b/src/main/java/tschipp/carryon/network/server/SyncKeybindPacketHandler.java new file mode 100644 index 0000000..5379a6c --- /dev/null +++ b/src/main/java/tschipp/carryon/network/server/SyncKeybindPacketHandler.java @@ -0,0 +1,34 @@ +package tschipp.carryon.network.server; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.util.IThreadListener; +import net.minecraft.world.WorldServer; +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; +import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; +import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; +import tschipp.carryon.client.keybinds.CarryOnKeybinds; + +public class SyncKeybindPacketHandler implements IMessageHandler +{ + + @Override + public IMessage onMessage(final SyncKeybindPacket message, final MessageContext ctx) + { + IThreadListener mainThread = (WorldServer) ctx.getServerHandler().playerEntity.world; + + mainThread.addScheduledTask(new Runnable() + { + EntityPlayerMP player = ctx.getServerHandler().playerEntity; + + @Override + public void run() + { + CarryOnKeybinds.setKeyPressed(player, message.pressed); + } + + }); + + return null; + } + +} diff --git a/src/main/resources/assets/carryon/lang/en_US.lang b/src/main/resources/assets/carryon/lang/en_US.lang index d0c67fb..5811dbb 100644 --- a/src/main/resources/assets/carryon/lang/en_US.lang +++ b/src/main/resources/assets/carryon/lang/en_US.lang @@ -8,3 +8,6 @@ carryon.general.blacklist.forbiddenentities=Entities that the Player cannot pick carryon.general.blacklist.forbiddentiles=Blocks that the Player cannot pick up carryon.category.custompickupconditions.custompickupconditionsblocks=Custom Block Pickup Conditions carryon.category.custompickupconditions.custompickupconditionsentities=Custom Entity Pickup Conditions + +key.carry.desc=Carry +key.carry.category=Carry On \ No newline at end of file From 66dffa73505caa2a0cdf3dd365d1c3157721b3e1 Mon Sep 17 00:00:00 2001 From: Tschipp Date: Sun, 27 Aug 2017 22:14:20 +0200 Subject: [PATCH 5/5] Fixed Keybinds and updated version number --- src/main/java/tschipp/carryon/CarryOn.java | 2 +- .../carryon/client/event/RenderEvents.java | 56 ++++++++++++++----- src/main/resources/mcmod.info | 2 +- 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/main/java/tschipp/carryon/CarryOn.java b/src/main/java/tschipp/carryon/CarryOn.java index f60d2d6..05ad90a 100644 --- a/src/main/java/tschipp/carryon/CarryOn.java +++ b/src/main/java/tschipp/carryon/CarryOn.java @@ -27,7 +27,7 @@ public class CarryOn { public static CarryOn instance; public static final String MODID = "carryon"; - public static final String VERSION = "1.2"; + public static final String VERSION = "1.3"; public static final String NAME = "Carry On"; public static final String UPDATE_JSON = "https://gist.githubusercontent.com/Tschipp/dccadee7c90d7a34e6e76a35d9d6fa2e/raw/"; public static final Logger LOGGER = LogManager.getFormatterLogger("CarryOn"); diff --git a/src/main/java/tschipp/carryon/client/event/RenderEvents.java b/src/main/java/tschipp/carryon/client/event/RenderEvents.java index 8d125cc..4d142af 100644 --- a/src/main/java/tschipp/carryon/client/event/RenderEvents.java +++ b/src/main/java/tschipp/carryon/client/event/RenderEvents.java @@ -1,8 +1,6 @@ package tschipp.carryon.client.event; import java.lang.reflect.Field; -import java.util.Iterator; -import java.util.List; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; @@ -36,13 +34,17 @@ import net.minecraftforge.client.event.RenderPlayerEvent; import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.InputEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import tschipp.carryon.CarryOn; +import tschipp.carryon.client.keybinds.CarryOnKeybinds; import tschipp.carryon.common.config.CarryOnConfig; import tschipp.carryon.common.handler.ModelOverridesHandler; import tschipp.carryon.common.handler.RegistrationHandler; import tschipp.carryon.common.item.ItemEntity; import tschipp.carryon.common.item.ItemTile; +import tschipp.carryon.network.server.SyncKeybindPacket; public class RenderEvents { @@ -65,6 +67,30 @@ public class RenderEvents } } + @SubscribeEvent + @SideOnly(Side.CLIENT) + public void onPlayerTick(PlayerTickEvent event) + { + EntityPlayer player = event.player; + if (player != null && event.side == Side.CLIENT) + { + + boolean keyPressed = CarryOnKeybinds.carryKey.isKeyDown(); + boolean playerKeyPressed = CarryOnKeybinds.isKeyPressed(player); + + if (keyPressed && !playerKeyPressed) + { + CarryOnKeybinds.setKeyPressed(player, true); + CarryOn.network.sendToServer(new SyncKeybindPacket(true)); + } + else if(!keyPressed && playerKeyPressed) + { + CarryOnKeybinds.setKeyPressed(player, false); + CarryOn.network.sendToServer(new SyncKeybindPacket(false)); + } + } + } + /* * Prevents the Player from opening Guis */ @@ -265,7 +291,6 @@ public class RenderEvents GlStateManager.popMatrix(); } - } /* @@ -276,7 +301,8 @@ public class RenderEvents public void onPlayerRenderPre(RenderPlayerEvent.Pre event) { - if (!Loader.isModLoaded("mobends") && CarryOnConfig.settings.renderArms) { + if (!Loader.isModLoaded("mobends") && CarryOnConfig.settings.renderArms) + { EntityPlayer player = event.getEntityPlayer(); AbstractClientPlayer aplayer = (AbstractClientPlayer) player; @@ -289,18 +315,20 @@ public class RenderEvents ModelRenderer fakeLeftArm = new ModelRenderer(model, 32, 48); ModelRenderer fakeRightArm = new ModelRenderer(model, 40, 16); - player.setArrowCountInEntity(0); //TODO Temporary Fix + player.setArrowCountInEntity(0); // TODO Temporary Fix if (!stack.isEmpty() && (stack.getItem() == RegistrationHandler.itemTile && ItemTile.hasTileData(stack)) || (stack.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack))) { if (model.bipedBody.childModels != null && !model.bipedBody.childModels.isEmpty()) { - for (int k = 0; k < model.bipedBody.childModels.size(); k++) { + for (int k = 0; k < model.bipedBody.childModels.size(); k++) + { float chkRot = model.bipedBody.childModels.get(k).rotateAngleX; - if (chkRot == -0.9001F || chkRot == -1.2001F || chkRot == -1.4001F || chkRot == -1.7001F) { + if (chkRot == -0.9001F || chkRot == -1.2001F || chkRot == -1.4001F || chkRot == -1.7001F) + { model.bipedBody.childModels.remove(k); - k = k -1; + k = k - 1; } } @@ -336,12 +364,12 @@ public class RenderEvents { if (!player.isSneaking()) { - fakeRightArm.rotateAngleX = -.9001F; + fakeRightArm.rotateAngleX = -.9001F; fakeLeftArm.rotateAngleX = -.9001F; } else { - fakeRightArm.rotateAngleX = -1.4001F; + fakeRightArm.rotateAngleX = -1.4001F; fakeLeftArm.rotateAngleX = -1.4001F; } } @@ -373,9 +401,11 @@ public class RenderEvents if (model.bipedBody.childModels != null && !model.bipedBody.childModels.isEmpty()) { - for (int k = 0; k < model.bipedBody.childModels.size(); k++) { + for (int k = 0; k < model.bipedBody.childModels.size(); k++) + { float chkRot = model.bipedBody.childModels.get(k).rotateAngleX; - if (chkRot == - 0.9001F || chkRot == -1.2001F || chkRot == -1.4001F || chkRot == -1.7001F) { + if (chkRot == -0.9001F || chkRot == -1.2001F || chkRot == -1.4001F || chkRot == -1.7001F) + { model.bipedBody.childModels.remove(k); k = k - 1; } @@ -383,7 +413,7 @@ public class RenderEvents } } - if (stack.isEmpty() || (stack.getItem() != RegistrationHandler.itemTile && stack.getItem() != RegistrationHandler.itemEntity)) + if (stack.isEmpty() || (stack.getItem() != RegistrationHandler.itemTile && stack.getItem() != RegistrationHandler.itemEntity)) { model.bipedLeftArm.isHidden = false; model.bipedRightArm.isHidden = false; diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index a373207..ffc74ba 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -2,7 +2,7 @@ { "modid" : "carryon", "name" : "Carry On", - "version" : "1.2", "mcversion" : "1.11.2", + "version" : "1.3", "mcversion" : "1.11.2", "url" : "", "credits" : "Tschipp, Purplicious_Cow, cy4n", "authorList" : ["Tschipp, Purplicious_Cow, cy4n"],