diff --git a/src/main/java/tschipp/carryon/client/event/RenderEntityEvents.java b/src/main/java/tschipp/carryon/client/event/RenderEntityEvents.java index 45e4ae2..0b3e309 100644 --- a/src/main/java/tschipp/carryon/client/event/RenderEntityEvents.java +++ b/src/main/java/tschipp/carryon/client/event/RenderEntityEvents.java @@ -164,7 +164,7 @@ public class RenderEntityEvents RenderHelper.enableStandardItemLighting(); Minecraft.getMinecraft().getRenderManager().setRenderShadow(false); - CarryOnOverride carryOverride = ScriptChecker.inspectEntity(entity); + CarryOnOverride carryOverride = ScriptChecker.getOverride(player); if (carryOverride != null) { double[] translation = ScriptParseHelper.getXYZArray(carryOverride.getRenderTranslation()); @@ -336,7 +336,7 @@ public class RenderEntityEvents Minecraft.getMinecraft().getRenderManager().setRenderShadow(false); - CarryOnOverride carryOverride = ScriptChecker.inspectEntity(entity); + CarryOnOverride carryOverride = ScriptChecker.getOverride(player); if (carryOverride != null) { double[] translation = ScriptParseHelper.getXYZArray(carryOverride.getRenderTranslation()); diff --git a/src/main/java/tschipp/carryon/client/event/RenderEvents.java b/src/main/java/tschipp/carryon/client/event/RenderEvents.java index 2351f58..c4fad5f 100644 --- a/src/main/java/tschipp/carryon/client/event/RenderEvents.java +++ b/src/main/java/tschipp/carryon/client/event/RenderEvents.java @@ -210,7 +210,7 @@ public class RenderEvents { IBakedModel model = ModelOverridesHandler.hasCustomOverrideModel(state, tag) ? ModelOverridesHandler.getCustomOverrideModel(state, tag, world, player) : Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(tileStack, world, player); - CarryOnOverride carryOverride = ScriptChecker.inspectBlock(state, world, player.getPosition(), tag); + CarryOnOverride carryOverride = ScriptChecker.getOverride(player); if (carryOverride != null) { double[] translation = ScriptParseHelper.getXYZArray(carryOverride.getRenderTranslation()); @@ -260,15 +260,16 @@ public class RenderEvents this.setLightmapDisabled(true); + if (perspective == 0) + { + event.setCanceled(true); + } + } GlStateManager.scale(1, 1, 1); GlStateManager.popMatrix(); - if (perspective == 0) - { - event.setCanceled(true); - } } else { @@ -376,7 +377,7 @@ public class RenderEvents IBakedModel model = ModelOverridesHandler.hasCustomOverrideModel(state, tag) ? ModelOverridesHandler.getCustomOverrideModel(state, tag, world, player) : Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(tileItem, world, player); - CarryOnOverride carryOverride = ScriptChecker.inspectBlock(state, world, player.getPosition(), tag); + CarryOnOverride carryOverride = ScriptChecker.getOverride(player); if (carryOverride != null) { double[] translation = ScriptParseHelper.getXYZArray(carryOverride.getRenderTranslation()); @@ -397,7 +398,7 @@ public class RenderEvents GlStateManager.scale(scale[0], scale[1], scale[2]); } - + if (ModelOverridesHandler.hasCustomOverrideModel(state, tag)) { Object override = ModelOverridesHandler.getOverrideObject(state, tag); @@ -449,16 +450,41 @@ public class RenderEvents 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()) + CarryOnOverride overrider = ScriptChecker.getOverride(player); + if (overrider != null) { - for (int k = 0; k < model.bipedBody.childModels.size(); k++) + if (model.bipedBody.childModels != null && !model.bipedBody.childModels.isEmpty()) { - float chkRot = model.bipedBody.childModels.get(k).rotateAngleX; - - if (chkRot == -0.9001F || chkRot == -1.2001F || chkRot == -1.4001F || chkRot == -1.7001F) + for (int k = 0; k < model.bipedBody.childModels.size(); k++) { - model.bipedBody.childModels.remove(k); - k = k - 1; + double[] rotLeft1 = ScriptParseHelper.getXYZArray(overrider.getRenderRotationLeftArm()); + double[] rotRight1 = ScriptParseHelper.getXYZArray(overrider.getRenderRotationRightArm()); + + float rotX = model.bipedBody.childModels.get(k).rotateAngleX; + float rotY = model.bipedBody.childModels.get(k).rotateAngleY; + float rotZ = model.bipedBody.childModels.get(k).rotateAngleZ; + + if (rotLeft1[0] == rotX || rotLeft1[1] == rotY || rotRight1[2] == rotZ || rotRight1[0] == rotX || rotRight1[1] == rotY || rotRight1[2] == rotZ || rotX == rotLeft1[0] - 0.5f || rotX == rotRight1[0] - 0.5f) + { + model.bipedBody.childModels.remove(k); + k = k - 1; + } + } + } + } + else + { + 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; + } } } } @@ -469,7 +495,11 @@ public class RenderEvents model.bipedRightArm.isHidden = true; model.bipedLeftArmwear.isHidden = true; model.bipedRightArmwear.isHidden = true; - + this.fakeLeftArm.isHidden = false; + this.fakeLeftArmwear.isHidden = false; + this.fakeRightArm.isHidden = false; + this.fakeRightArmwear.isHidden = false; + Minecraft.getMinecraft().getTextureManager().bindTexture(skinLoc); if (aplayer.getSkinType().equals("default")) @@ -493,44 +523,190 @@ public class RenderEvents this.fakeRightArmwear.addBox(model.bipedRightArm.offsetX - 7.2F, model.bipedRightArm.offsetY, model.bipedRightArm.offsetZ, 3, 12, 4, .08F + 0.25F); } - if (item == RegistrationHandler.itemTile) + CarryOnOverride override = ScriptChecker.getOverride(player); + if (override != null) { - if (!player.isSneaking()) + double[] rotLeft = null; + double[] rotRight = null; + if (override.getRenderRotationLeftArm() != null) + rotLeft = ScriptParseHelper.getXYZArray(override.getRenderRotationLeftArm()); + if (override.getRenderRotationRightArm() != null) + rotRight = ScriptParseHelper.getXYZArray(override.getRenderRotationRightArm()); + + boolean renderRight = override.isRenderRightArm(); + boolean renderLeft = override.isRenderLeftArm(); + + if (!renderRight) { - this.fakeRightArm.rotateAngleX = -.9001F; - this.fakeLeftArm.rotateAngleX = -.9001F; - this.fakeLeftArmwear.rotateAngleX = -.9001F; - this.fakeRightArmwear.rotateAngleX = -.9001F; + this.fakeRightArm.isHidden = true; + this.fakeRightArmwear.isHidden = true; + model.bipedRightArm.isHidden = false; + model.bipedRightArmwear.isHidden = false; + } + + + if (!renderLeft) + { + this.fakeLeftArm.isHidden = true; + this.fakeLeftArmwear.isHidden = true; + model.bipedLeftArm.isHidden = false; + model.bipedLeftArmwear.isHidden = false; + } + + + if (rotLeft != null) + { + if (!player.isSneaking()) + { + this.fakeLeftArm.rotateAngleX = (float) rotLeft[0]; + this.fakeLeftArmwear.rotateAngleX = (float) rotLeft[0]; + } + else + { + this.fakeLeftArm.rotateAngleX = (float) rotLeft[0] - 0.5f; + this.fakeLeftArmwear.rotateAngleX = (float) rotLeft[0] - 0.5f; + } + + this.fakeLeftArmwear.rotateAngleY = (float) rotLeft[1]; + this.fakeLeftArmwear.rotateAngleZ = (float) rotLeft[2]; + this.fakeLeftArm.rotateAngleY = (float) rotLeft[1]; + this.fakeLeftArm.rotateAngleZ = (float) rotLeft[2]; } else { - this.fakeRightArm.rotateAngleX = -1.4001F; - this.fakeLeftArm.rotateAngleX = -1.4001F; - this.fakeLeftArmwear.rotateAngleX = -1.4001F; - this.fakeRightArmwear.rotateAngleX = -1.4001F; + if (item == RegistrationHandler.itemTile) + { + if (!player.isSneaking()) + { + this.fakeLeftArm.rotateAngleX = -.9001F; + this.fakeLeftArmwear.rotateAngleX = -.9001F; + } + else + { + this.fakeLeftArm.rotateAngleX = -1.4001F; + this.fakeLeftArmwear.rotateAngleX = -1.4001F; + } + } + else + { + if (!player.isSneaking()) + { + this.fakeLeftArm.rotateAngleX = -1.2001F; + this.fakeLeftArmwear.rotateAngleX = -1.2001F; + } + else + { + this.fakeLeftArm.rotateAngleX = -1.7001F; + this.fakeLeftArmwear.rotateAngleX = -1.7001F; + } + + this.fakeLeftArm.rotateAngleY = 0.15f; + this.fakeLeftArmwear.rotateAngleY = 0.15f; + } + } + + if (rotRight != null) + { + if (!player.isSneaking()) + { + this.fakeRightArm.rotateAngleX = (float) rotRight[0]; + this.fakeRightArmwear.rotateAngleX = (float) rotRight[0]; + } + else + { + this.fakeRightArm.rotateAngleX = (float) rotRight[0] - 0.5f; + this.fakeRightArmwear.rotateAngleX = (float) rotRight[0] - 0.5f; + } + + this.fakeRightArmwear.rotateAngleY = (float) rotRight[1]; + this.fakeRightArmwear.rotateAngleZ = (float) rotRight[2]; + this.fakeRightArm.rotateAngleY = (float) rotRight[1]; + this.fakeRightArm.rotateAngleZ = (float) rotRight[2]; + } + else + { + if (item == RegistrationHandler.itemTile) + { + if (!player.isSneaking()) + { + this.fakeRightArm.rotateAngleX = -.9001F; + this.fakeRightArmwear.rotateAngleX = -.9001F; + } + else + { + this.fakeRightArm.rotateAngleX = -1.4001F; + this.fakeRightArmwear.rotateAngleX = -1.4001F; + } + } + else + { + if (!player.isSneaking()) + { + this.fakeRightArm.rotateAngleX = -1.2001F; + this.fakeRightArmwear.rotateAngleX = -1.2001F; + } + else + { + this.fakeRightArm.rotateAngleX = -1.7001F; + this.fakeRightArmwear.rotateAngleX = -1.7001F; + } + + this.fakeRightArm.rotateAngleY = -0.15f; + this.fakeRightArmwear.rotateAngleY = -0.15f; + } } } else { - if (!player.isSneaking()) + if (item == RegistrationHandler.itemTile) { - this.fakeRightArm.rotateAngleX = -1.2001F; - this.fakeLeftArm.rotateAngleX = -1.2001F; - this.fakeLeftArmwear.rotateAngleX = -1.2001F; - this.fakeRightArmwear.rotateAngleX = -1.2001F; + if (!player.isSneaking()) + { + this.fakeRightArm.rotateAngleX = -.9001F; + this.fakeLeftArm.rotateAngleX = -.9001F; + this.fakeLeftArmwear.rotateAngleX = -.9001F; + this.fakeRightArmwear.rotateAngleX = -.9001F; + } + else + { + this.fakeRightArm.rotateAngleX = -1.4001F; + this.fakeLeftArm.rotateAngleX = -1.4001F; + this.fakeLeftArmwear.rotateAngleX = -1.4001F; + this.fakeRightArmwear.rotateAngleX = -1.4001F; + } + + this.fakeRightArm.rotateAngleY = 0f; + this.fakeLeftArm.rotateAngleY = 0f; + this.fakeLeftArmwear.rotateAngleY = 0f; + this.fakeRightArmwear.rotateAngleY = 0f; } else { - this.fakeRightArm.rotateAngleX = -1.7001F; - this.fakeLeftArm.rotateAngleX = -1.7001F; - this.fakeLeftArmwear.rotateAngleX = -1.7001F; - this.fakeRightArmwear.rotateAngleX = -1.7001F; + if (!player.isSneaking()) + { + this.fakeRightArm.rotateAngleX = -1.2001F; + this.fakeLeftArm.rotateAngleX = -1.2001F; + this.fakeLeftArmwear.rotateAngleX = -1.2001F; + this.fakeRightArmwear.rotateAngleX = -1.2001F; + } + else + { + this.fakeRightArm.rotateAngleX = -1.7001F; + this.fakeLeftArm.rotateAngleX = -1.7001F; + this.fakeLeftArmwear.rotateAngleX = -1.7001F; + this.fakeRightArmwear.rotateAngleX = -1.7001F; + } + + this.fakeRightArm.rotateAngleY = -0.15f; + this.fakeLeftArm.rotateAngleY = 0.15f; + this.fakeLeftArmwear.rotateAngleY = 0.15f; + this.fakeRightArmwear.rotateAngleY = -0.15f; } - this.fakeRightArm.rotateAngleY = -0.15f; - this.fakeLeftArm.rotateAngleY = 0.15f; - this.fakeLeftArmwear.rotateAngleY = 0.15f; - this.fakeRightArmwear.rotateAngleY = -0.15f; + this.fakeRightArm.rotateAngleZ = 0F; + this.fakeLeftArm.rotateAngleZ = 0F; + this.fakeLeftArmwear.rotateAngleZ = 0F; + this.fakeRightArmwear.rotateAngleZ = 0F; } model.bipedBody.addChild(this.fakeLeftArm); @@ -552,16 +728,41 @@ public class RenderEvents model.bipedLeftArmwear.isHidden = false; model.bipedRightArmwear.isHidden = false; - if (model.bipedBody.childModels != null && !model.bipedBody.childModels.isEmpty()) + CarryOnOverride overrider = ScriptChecker.getOverride(player); + if (overrider != null) { - for (int k = 0; k < model.bipedBody.childModels.size(); k++) + if (model.bipedBody.childModels != null && !model.bipedBody.childModels.isEmpty()) { - float chkRot = model.bipedBody.childModels.get(k).rotateAngleX; - - if (chkRot == -0.9001F || chkRot == -1.2001F || chkRot == -1.4001F || chkRot == -1.7001F) + for (int k = 0; k < model.bipedBody.childModels.size(); k++) { - model.bipedBody.childModels.remove(k); - k = k - 1; + double[] rotLeft1 = ScriptParseHelper.getXYZArray(overrider.getRenderRotationLeftArm()); + double[] rotRight1 = ScriptParseHelper.getXYZArray(overrider.getRenderRotationRightArm()); + + float rotX = model.bipedBody.childModels.get(k).rotateAngleX; + float rotY = model.bipedBody.childModels.get(k).rotateAngleY; + float rotZ = model.bipedBody.childModels.get(k).rotateAngleZ; + + if (rotLeft1[0] == rotX || rotLeft1[1] == rotY || rotRight1[2] == rotZ || rotRight1[0] == rotX || rotRight1[1] == rotY || rotRight1[2] == rotZ || rotX == rotLeft1[0] - 0.5f || rotX == rotRight1[0] - 0.5f) + { + model.bipedBody.childModels.remove(k); + k = k - 1; + } + } + } + } + else + { + 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; + } } } } diff --git a/src/main/java/tschipp/carryon/common/command/CommandCarryOn.java b/src/main/java/tschipp/carryon/common/command/CommandCarryOn.java index 81d316b..fc574a8 100644 --- a/src/main/java/tschipp/carryon/common/command/CommandCarryOn.java +++ b/src/main/java/tschipp/carryon/common/command/CommandCarryOn.java @@ -136,11 +136,6 @@ public class CommandCarryOn extends CommandBase implements ICommand } } } - else if (args[0].toLowerCase().equals("reload")) - { - ScriptReader.reloadScripts(); - sender.sendMessage(new TextComponentString("Successfully reloaded Scripts!")); - } else { throw new WrongUsageException(this.getUsage(sender)); diff --git a/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java b/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java index a3b9956..c35ca3d 100644 --- a/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java +++ b/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java @@ -25,6 +25,8 @@ import tschipp.carryon.client.keybinds.CarryOnKeybinds; import tschipp.carryon.common.handler.PickupHandler; import tschipp.carryon.common.handler.RegistrationHandler; import tschipp.carryon.common.item.ItemEntity; +import tschipp.carryon.common.scripting.CarryOnOverride; +import tschipp.carryon.common.scripting.ScriptChecker; import tschipp.carryon.network.client.CarrySlotPacket; public class ItemEntityEvents @@ -97,7 +99,13 @@ public class ItemEntityEvents handler.extractItem(i, 64, false); } } - CarryOn.network.sendTo(new CarrySlotPacket(player.inventory.currentItem), (EntityPlayerMP) player); + + CarryOnOverride override = ScriptChecker.inspectEntity(entity); + int overrideHash = 0; + if(override != null) + overrideHash = override.hashCode(); + + CarryOn.network.sendTo(new CarrySlotPacket(player.inventory.currentItem, overrideHash), (EntityPlayerMP) player); entity.setDead(); player.setHeldItem(EnumHand.MAIN_HAND, stack); event.setCanceled(true); diff --git a/src/main/java/tschipp/carryon/common/event/ItemEvents.java b/src/main/java/tschipp/carryon/common/event/ItemEvents.java index 7b5344c..f063e8f 100644 --- a/src/main/java/tschipp/carryon/common/event/ItemEvents.java +++ b/src/main/java/tschipp/carryon/common/event/ItemEvents.java @@ -29,6 +29,8 @@ import tschipp.carryon.common.handler.ListHandler; import tschipp.carryon.common.handler.PickupHandler; import tschipp.carryon.common.handler.RegistrationHandler; import tschipp.carryon.common.item.ItemTile; +import tschipp.carryon.common.scripting.CarryOnOverride; +import tschipp.carryon.common.scripting.ScriptChecker; import tschipp.carryon.network.client.CarrySlotPacket; public class ItemEvents @@ -114,10 +116,14 @@ public class ItemEvents IBlockState statee = world.getBlockState(pos); NBTTagCompound tag = new NBTTagCompound(); tag = world.getTileEntity(pos) != null ? world.getTileEntity(pos).writeToNBT(tag) : new NBTTagCompound(); - + CarryOnOverride override = ScriptChecker.inspectBlock(state, world, pos, tag); + int overrideHash = 0; + if(override != null) + overrideHash = override.hashCode(); + try { - CarryOn.network.sendTo(new CarrySlotPacket(player.inventory.currentItem), (EntityPlayerMP) player); + CarryOn.network.sendTo(new CarrySlotPacket(player.inventory.currentItem, overrideHash), (EntityPlayerMP) player); world.removeTileEntity(pos); world.setBlockToAir(pos); player.setHeldItem(EnumHand.MAIN_HAND, stack); diff --git a/src/main/java/tschipp/carryon/common/helper/ScriptParseHelper.java b/src/main/java/tschipp/carryon/common/helper/ScriptParseHelper.java index 4155be2..f1c4db5 100644 --- a/src/main/java/tschipp/carryon/common/helper/ScriptParseHelper.java +++ b/src/main/java/tschipp/carryon/common/helper/ScriptParseHelper.java @@ -24,19 +24,19 @@ public class ScriptParseHelper { if (cond.contains("<=")) { - return number >= Double.parseDouble(cond.replace("<=", "")); + return number <= Double.parseDouble(cond.replace("<=", "")); } if (cond.contains(">=")) { - return number <= Double.parseDouble(cond.replace(">=", "")); + return number >= Double.parseDouble(cond.replace(">=", "")); } if (cond.contains("<")) { - return number > Double.parseDouble(cond.replace("<", "")); + return number < Double.parseDouble(cond.replace("<", "")); } if (cond.contains(">")) { - return number < Double.parseDouble(cond.replace(">", "")); + return number > Double.parseDouble(cond.replace(">", "")); } if (cond.contains("=")) { diff --git a/src/main/java/tschipp/carryon/common/item/ItemEntity.java b/src/main/java/tschipp/carryon/common/item/ItemEntity.java index dd31169..297a033 100644 --- a/src/main/java/tschipp/carryon/common/item/ItemEntity.java +++ b/src/main/java/tschipp/carryon/common/item/ItemEntity.java @@ -111,6 +111,7 @@ public class ItemEntity extends Item clearEntityData(stack); player.setHeldItem(hand, ItemStack.EMPTY); } + player.getEntityData().removeTag("overrideKey"); return EnumActionResult.SUCCESS; } } diff --git a/src/main/java/tschipp/carryon/common/item/ItemTile.java b/src/main/java/tschipp/carryon/common/item/ItemTile.java index df788b7..8e810af 100644 --- a/src/main/java/tschipp/carryon/common/item/ItemTile.java +++ b/src/main/java/tschipp/carryon/common/item/ItemTile.java @@ -143,6 +143,7 @@ public class ItemTile extends Item clearTileData(stack); player.playSound(containedblock.getSoundType().getPlaceSound(), 1.0f, 0.5f); player.setHeldItem(hand, ItemStack.EMPTY); + player.getEntityData().removeTag("overrideKey"); return EnumActionResult.SUCCESS; } diff --git a/src/main/java/tschipp/carryon/common/scripting/CarryOnOverride.java b/src/main/java/tschipp/carryon/common/scripting/CarryOnOverride.java index 7d6ef3c..b3bda35 100644 --- a/src/main/java/tschipp/carryon/common/scripting/CarryOnOverride.java +++ b/src/main/java/tschipp/carryon/common/scripting/CarryOnOverride.java @@ -4,7 +4,7 @@ import net.minecraft.nbt.NBTTagCompound; public class CarryOnOverride { - //BLOCKS + // BLOCKS private NBTTagCompound typeBlockTag; private String typeMeta; private String typeNameBlock; @@ -12,14 +12,14 @@ public class CarryOnOverride private String typeHardness; private String typeResistance; - //ENTITIES + // ENTITIES private NBTTagCompound typeEntityTag; private String typeNameEntity; private String typeHeight; private String typeWidth; private String typeHealth; - - //CONDITIONS + + // CONDITIONS private String conditionGamestage; private String conditionAchievement; private String conditionXp; @@ -27,7 +27,7 @@ public class CarryOnOverride private String conditionScoreboard; private String conditionPosition; - //RENDER + // RENDER private String renderNameBlock; private String renderNameEntity; private int renderMeta; @@ -35,225 +35,545 @@ public class CarryOnOverride private String renderTranslation; private String renderRotation; private String renderScale; - + private String renderRotationLeftArm; + private String renderRotationRightArm; + private boolean isBlock; private boolean isEntity; + + private boolean renderLeftArm = true; + private boolean renderRightArm = true; + + public String getRenderRotationLeftArm() + { + return renderRotationLeftArm; + } + + public void setRenderRotationLeftArm(String renderRotationLeftArm) + { + this.renderRotationLeftArm = renderRotationLeftArm; + } + + public String getRenderRotationRightArm() + { + return renderRotationRightArm; + } + + public void setRenderRotationRightArm(String renderRotationRightArm) + { + this.renderRotationRightArm = renderRotationRightArm; + } + + public boolean isRenderLeftArm() + { + return renderLeftArm; + } + + public void setRenderLeftArm(boolean renderLeftArm) + { + this.renderLeftArm = renderLeftArm; + } + + public boolean isRenderRightArm() + { + return renderRightArm; + } + + public void setRenderRightArm(boolean renderRightArm) + { + this.renderRightArm = renderRightArm; + } + + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + ((conditionAchievement == null) ? 0 : conditionAchievement.hashCode()); + result = prime * result + ((conditionGamemode == null) ? 0 : conditionGamemode.hashCode()); + result = prime * result + ((conditionGamestage == null) ? 0 : conditionGamestage.hashCode()); + result = prime * result + ((conditionPosition == null) ? 0 : conditionPosition.hashCode()); + result = prime * result + ((conditionScoreboard == null) ? 0 : conditionScoreboard.hashCode()); + result = prime * result + ((conditionXp == null) ? 0 : conditionXp.hashCode()); + result = prime * result + (isBlock ? 1231 : 1237); + result = prime * result + (isEntity ? 1231 : 1237); + result = prime * result + (renderLeftArm ? 1231 : 1237); + result = prime * result + (renderRightArm ? 1231 : 1237); + result = prime * result + renderMeta; + result = prime * result + ((renderNBT == null) ? 0 : renderNBT.hashCode()); + result = prime * result + ((renderNameBlock == null) ? 0 : renderNameBlock.hashCode()); + result = prime * result + ((renderNameEntity == null) ? 0 : renderNameEntity.hashCode()); + result = prime * result + ((renderRotation == null) ? 0 : renderRotation.hashCode()); + result = prime * result + ((renderRotationLeftArm == null) ? 0 : renderRotationLeftArm.hashCode()); + result = prime * result + ((renderRotationRightArm == null) ? 0 : renderRotationRightArm.hashCode()); + result = prime * result + ((renderScale == null) ? 0 : renderScale.hashCode()); + result = prime * result + ((renderTranslation == null) ? 0 : renderTranslation.hashCode()); + result = prime * result + ((typeBlockTag == null) ? 0 : typeBlockTag.hashCode()); + result = prime * result + ((typeEntityTag == null) ? 0 : typeEntityTag.hashCode()); + result = prime * result + ((typeHardness == null) ? 0 : typeHardness.hashCode()); + result = prime * result + ((typeHealth == null) ? 0 : typeHealth.hashCode()); + result = prime * result + ((typeHeight == null) ? 0 : typeHeight.hashCode()); + result = prime * result + ((typeMaterial == null) ? 0 : typeMaterial.hashCode()); + result = prime * result + ((typeMeta == null) ? 0 : typeMeta.hashCode()); + result = prime * result + ((typeNameBlock == null) ? 0 : typeNameBlock.hashCode()); + result = prime * result + ((typeNameEntity == null) ? 0 : typeNameEntity.hashCode()); + result = prime * result + ((typeResistance == null) ? 0 : typeResistance.hashCode()); + result = prime * result + ((typeWidth == null) ? 0 : typeWidth.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CarryOnOverride other = (CarryOnOverride) obj; + if (conditionAchievement == null) + { + if (other.conditionAchievement != null) + return false; + } + else if (!conditionAchievement.equals(other.conditionAchievement)) + return false; + if (conditionGamemode == null) + { + if (other.conditionGamemode != null) + return false; + } + else if (!conditionGamemode.equals(other.conditionGamemode)) + return false; + if (conditionGamestage == null) + { + if (other.conditionGamestage != null) + return false; + } + else if (!conditionGamestage.equals(other.conditionGamestage)) + return false; + if (conditionPosition == null) + { + if (other.conditionPosition != null) + return false; + } + else if (!conditionPosition.equals(other.conditionPosition)) + return false; + if (conditionScoreboard == null) + { + if (other.conditionScoreboard != null) + return false; + } + else if (!conditionScoreboard.equals(other.conditionScoreboard)) + return false; + if (conditionXp == null) + { + if (other.conditionXp != null) + return false; + } + else if (!conditionXp.equals(other.conditionXp)) + return false; + if (isBlock != other.isBlock) + return false; + if (isEntity != other.isEntity) + return false; + if (renderMeta != other.renderMeta) + return false; + if (renderNBT == null) + { + if (other.renderNBT != null) + return false; + } + else if (!renderNBT.equals(other.renderNBT)) + return false; + if (renderNameBlock == null) + { + if (other.renderNameBlock != null) + return false; + } + else if (!renderNameBlock.equals(other.renderNameBlock)) + return false; + if (renderNameEntity == null) + { + if (other.renderNameEntity != null) + return false; + } + else if (!renderNameEntity.equals(other.renderNameEntity)) + return false; + if (renderRotation == null) + { + if (other.renderRotation != null) + return false; + } + else if (!renderRotation.equals(other.renderRotation)) + return false; + if (renderRotationLeftArm == null) + { + if (other.renderRotationLeftArm != null) + return false; + } + else if (!renderRotationLeftArm.equals(other.renderRotationLeftArm)) + return false; + if (renderRotationRightArm == null) + { + if (other.renderRotationRightArm != null) + return false; + } + else if (!renderRotationRightArm.equals(other.renderRotationRightArm)) + return false; + if (renderScale == null) + { + if (other.renderScale != null) + return false; + } + else if (!renderScale.equals(other.renderScale)) + return false; + if (renderTranslation == null) + { + if (other.renderTranslation != null) + return false; + } + else if (!renderTranslation.equals(other.renderTranslation)) + return false; + if (typeBlockTag == null) + { + if (other.typeBlockTag != null) + return false; + } + else if (!typeBlockTag.equals(other.typeBlockTag)) + return false; + if (typeEntityTag == null) + { + if (other.typeEntityTag != null) + return false; + } + else if (!typeEntityTag.equals(other.typeEntityTag)) + return false; + if (typeHardness == null) + { + if (other.typeHardness != null) + return false; + } + else if (!typeHardness.equals(other.typeHardness)) + return false; + if (typeHealth == null) + { + if (other.typeHealth != null) + return false; + } + else if (!typeHealth.equals(other.typeHealth)) + return false; + if (typeHeight == null) + { + if (other.typeHeight != null) + return false; + } + else if (!typeHeight.equals(other.typeHeight)) + return false; + if (typeMaterial == null) + { + if (other.typeMaterial != null) + return false; + } + else if (!typeMaterial.equals(other.typeMaterial)) + return false; + if (typeMeta == null) + { + if (other.typeMeta != null) + return false; + } + else if (!typeMeta.equals(other.typeMeta)) + return false; + if (typeNameBlock == null) + { + if (other.typeNameBlock != null) + return false; + } + else if (!typeNameBlock.equals(other.typeNameBlock)) + return false; + if (typeNameEntity == null) + { + if (other.typeNameEntity != null) + return false; + } + else if (!typeNameEntity.equals(other.typeNameEntity)) + return false; + if (typeResistance == null) + { + if (other.typeResistance != null) + return false; + } + else if (!typeResistance.equals(other.typeResistance)) + return false; + if (typeWidth == null) + { + if (other.typeWidth != null) + return false; + } + else if (!typeWidth.equals(other.typeWidth)) + return false; + return true; + } - - - - - - public boolean isBlock() { return isBlock; } + public void setBlock(boolean isBlock) { this.isBlock = isBlock; } + public boolean isEntity() { return isEntity; } + public void setEntity(boolean isEntity) { this.isEntity = isEntity; } + public NBTTagCompound getTypeBlockTag() { return typeBlockTag; } + public String getTypeMeta() { return typeMeta; } + public String getTypeNameBlock() { return typeNameBlock; } + public String getTypeMaterial() { return typeMaterial; } + public String getTypeHardness() { return typeHardness; } + public String getTypeResistance() { return typeResistance; } + public NBTTagCompound getTypeEntityTag() { return typeEntityTag; } + public String getTypeNameEntity() { return typeNameEntity; } + public String getTypeHeight() { return typeHeight; } + public String getTypeWidth() { return typeWidth; } + public String getTypeHealth() { return typeHealth; } + public String getConditionGamestage() { return conditionGamestage; } + public String getConditionAchievement() { return conditionAchievement; } + public String getConditionXp() { return conditionXp; } + public String getConditionGamemode() { return conditionGamemode; } + public String getConditionScoreboard() { return conditionScoreboard; } + public String getConditionPosition() { return conditionPosition; } + public String getRenderNameBlock() { return renderNameBlock; } + public String getRenderNameEntity() { return renderNameEntity; } + public int getRenderMeta() { return renderMeta; } + public NBTTagCompound getRenderNBT() { return renderNBT; } + public String getRenderTranslation() { return renderTranslation; } + public String getRenderRotation() { return renderRotation; } + public String getRenderScale() { return renderScale; } + public void setTypeBlockTag(NBTTagCompound typeBlockTag) { this.typeBlockTag = typeBlockTag; } + public void setTypeMeta(String typeMeta) { this.typeMeta = typeMeta; } + public void setTypeNameBlock(String typeNameBlock) { this.typeNameBlock = typeNameBlock; } + public void setTypeMaterial(String typeMaterial) { this.typeMaterial = typeMaterial; } + public void setTypeHardness(String typeHardness) { this.typeHardness = typeHardness; } + public void setTypeResistance(String typeResistance) { this.typeResistance = typeResistance; } + public void setTypeEntityTag(NBTTagCompound typeEntityTag) { this.typeEntityTag = typeEntityTag; } + public void setTypeNameEntity(String typeNameEntity) { this.typeNameEntity = typeNameEntity; } + public void setTypeHeight(String typeHeight) { this.typeHeight = typeHeight; } + public void setTypeWidth(String typeWidth) { this.typeWidth = typeWidth; } + public void setTypeHealth(String typeHealth) { this.typeHealth = typeHealth; } + public void setConditionGamestage(String conditionGamestage) { this.conditionGamestage = conditionGamestage; } + public void setConditionAchievement(String conditionAchievement) { this.conditionAchievement = conditionAchievement; } + public void setConditionXp(String conditionXp) { this.conditionXp = conditionXp; } + public void setConditionGamemode(String conditionGamemode) { this.conditionGamemode = conditionGamemode; } + public void setConditionScoreboard(String conditionScoreboard) { this.conditionScoreboard = conditionScoreboard; } + public void setConditionPosition(String conditionPosition) { this.conditionPosition = conditionPosition; } + public void setRenderNameBlock(String renderNameBlock) { this.renderNameBlock = renderNameBlock; } + public void setRenderNameEntity(String renderNameEntity) { this.renderNameEntity = renderNameEntity; } + public void setRenderMeta(int renderMeta) { this.renderMeta = renderMeta; } + public void setRenderNBT(NBTTagCompound renderNBT) { this.renderNBT = renderNBT; } + public void setRenderTranslation(String renderTranslation) { this.renderTranslation = renderTranslation; } + public void setRenderRotation(String renderRotation) { this.renderRotation = renderRotation; } + public void setRenderScale(String renderScale) { this.renderScale = renderScale; } - - } diff --git a/src/main/java/tschipp/carryon/common/scripting/ScriptChecker.java b/src/main/java/tschipp/carryon/common/scripting/ScriptChecker.java index f84ef21..353b9f6 100644 --- a/src/main/java/tschipp/carryon/common/scripting/ScriptChecker.java +++ b/src/main/java/tschipp/carryon/common/scripting/ScriptChecker.java @@ -37,7 +37,7 @@ public class ScriptChecker float resistance = block.getExplosionResistance(null); NBTTagCompound nbt = tag; - for (CarryOnOverride override : ScriptReader.OVERRIDES) + for (CarryOnOverride override : ScriptReader.OVERRIDES.values()) { if (override.isBlock()) { @@ -62,7 +62,7 @@ public class ScriptChecker NBTTagCompound tag = new NBTTagCompound(); entity.writeToNBT(tag); - for (CarryOnOverride override : ScriptReader.OVERRIDES) + for (CarryOnOverride override : ScriptReader.OVERRIDES.values()) { if (override.isEntity()) { @@ -76,7 +76,7 @@ public class ScriptChecker public static boolean matchesAll(CarryOnOverride override, String name, float height, float width, float health, NBTTagCompound tag) { - boolean matchname = name == null ? true : name.equals(override.getTypeNameEntity()); + boolean matchname = override.getTypeNameEntity() == null ? true : name.equals(override.getTypeNameEntity()); boolean matchheight = ScriptParseHelper.matches(height, override.getTypeHeight()); boolean matchwidth = ScriptParseHelper.matches(width, override.getTypeWidth()); boolean matchhealth = ScriptParseHelper.matches(health, override.getTypeHealth()); @@ -111,4 +111,28 @@ public class ScriptChecker return (achievement && gamemode && gamestage && position && xp && scoreboard); } + + @Nullable + public static CarryOnOverride getOverride(EntityPlayer player) + { + NBTTagCompound tag = player.getEntityData(); + + if (tag != null && tag.hasKey("overrideKey")) + { + int key = tag.getInteger("overrideKey"); + + return ScriptReader.OVERRIDES.get(key); + } + + return null; + } + + public static void setCarryOnOverride(EntityPlayer player, int i) + { + NBTTagCompound tag = player.getEntityData(); + + if (tag != null) + tag.setInteger("overrideKey", i); + } + } diff --git a/src/main/java/tschipp/carryon/common/scripting/ScriptReader.java b/src/main/java/tschipp/carryon/common/scripting/ScriptReader.java index a7f3e20..1b18bb4 100644 --- a/src/main/java/tschipp/carryon/common/scripting/ScriptReader.java +++ b/src/main/java/tschipp/carryon/common/scripting/ScriptReader.java @@ -15,7 +15,6 @@ import com.google.gson.JsonSyntaxException; import net.minecraft.nbt.JsonToNBT; import net.minecraft.nbt.NBTException; -import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import tschipp.carryon.CarryOn; import tschipp.carryon.common.config.CarryOnConfig; @@ -23,8 +22,9 @@ import tschipp.carryon.common.config.CarryOnConfig; public class ScriptReader { private static ArrayList scripts = new ArrayList(); - - public static HashSet OVERRIDES = new HashSet(); + public static HashMap OVERRIDES = new HashMap(); + + //public static HashSet OVERRIDES = new HashSet(); public static void preInit(FMLPreInitializationEvent event) { @@ -145,6 +145,10 @@ public class ScriptReader JsonElement translation = render.get("translation"); JsonElement rotation = render.get("rotation"); JsonElement scale = render.get("scale"); + JsonElement rotationLeftArm = render.get("rotation_left_arm"); + JsonElement rotationRightArm = render.get("rotation_right_arm"); + JsonElement renderLeftArm = render.get("render_left_arm"); + JsonElement renderRightArm = render.get("render_right_arm"); if(name_block != null) override.setRenderNameBlock(name_block.getAsString()); @@ -160,9 +164,17 @@ public class ScriptReader override.setRenderScale(scale.getAsString()); if (nbt != null) override.setRenderNBT(JsonToNBT.getTagFromJson(nbt.toString())); + if(rotationLeftArm != null) + override.setRenderRotationLeftArm(rotationLeftArm.getAsString()); + if(rotationRightArm != null) + override.setRenderRotationRightArm(rotationRightArm.getAsString()); + if(renderLeftArm != null) + override.setRenderLeftArm(renderLeftArm.getAsBoolean()); + if(renderRightArm != null) + override.setRenderRightArm(renderRightArm.getAsBoolean()); } - OVERRIDES.add(override); + OVERRIDES.put(override.hashCode(), override); } } diff --git a/src/main/java/tschipp/carryon/network/client/CarrySlotPacket.java b/src/main/java/tschipp/carryon/network/client/CarrySlotPacket.java index 1f53e07..ca9fb2f 100644 --- a/src/main/java/tschipp/carryon/network/client/CarrySlotPacket.java +++ b/src/main/java/tschipp/carryon/network/client/CarrySlotPacket.java @@ -1,12 +1,14 @@ package tschipp.carryon.network.client; import io.netty.buffer.ByteBuf; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fml.common.network.ByteBufUtils; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; public class CarrySlotPacket implements IMessage { public int slot; + public int carryOverride = 0; public CarrySlotPacket() { @@ -16,17 +18,30 @@ public class CarrySlotPacket implements IMessage { this.slot = slot; } + + public CarrySlotPacket(int slot, int carryOverride) + { + this.slot = slot; + this.carryOverride = carryOverride; + } @Override public void fromBytes(ByteBuf buf) { - this.slot = ByteBufUtils.readVarInt(buf, 4); + NBTTagCompound tag = ByteBufUtils.readTag(buf); + + this.slot = tag.getInteger("slot"); + this.carryOverride = tag.getInteger("override"); } @Override public void toBytes(ByteBuf buf) { - ByteBufUtils.writeVarInt(buf, slot, 4); + NBTTagCompound tag = new NBTTagCompound(); + tag.setInteger("slot", slot); + tag.setInteger("override", carryOverride); + ByteBufUtils.writeTag(buf, tag); + } } diff --git a/src/main/java/tschipp/carryon/network/client/CarrySlotPacketHandler.java b/src/main/java/tschipp/carryon/network/client/CarrySlotPacketHandler.java index 6acdadb..7e7ff43 100644 --- a/src/main/java/tschipp/carryon/network/client/CarrySlotPacketHandler.java +++ b/src/main/java/tschipp/carryon/network/client/CarrySlotPacketHandler.java @@ -7,6 +7,7 @@ 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; +import tschipp.carryon.common.scripting.ScriptChecker; public class CarrySlotPacketHandler implements IMessageHandler { @@ -24,9 +25,19 @@ public class CarrySlotPacketHandler implements IMessageHandler= 9) + { player.getEntityData().removeTag("carrySlot"); + player.getEntityData().removeTag("overrideKey"); + } else + { player.getEntityData().setInteger("carrySlot", message.slot); + if(message.carryOverride != 0) + ScriptChecker.setCarryOnOverride(player, message.carryOverride); + } + + + } });