diff --git a/src/main/java/tconstruct/TConstruct.java b/src/main/java/tconstruct/TConstruct.java index 24d7987c..5fcd636d 100644 --- a/src/main/java/tconstruct/TConstruct.java +++ b/src/main/java/tconstruct/TConstruct.java @@ -27,6 +27,8 @@ import tconstruct.armor.TinkerArmor; import tconstruct.armor.player.TPlayerHandler; import tconstruct.armor.player.TPlayerStats; import tconstruct.common.TProxyCommon; +import tconstruct.gadgets.TinkerGadgets; +import tconstruct.library.SlimeBounceHandler; import tconstruct.library.TConstructCreativeTab; import tconstruct.library.TConstructRegistry; import tconstruct.library.crafting.Detailing; @@ -148,6 +150,7 @@ public class TConstruct pulsar.registerPulse(new TinkerMechworks()); pulsar.registerPulse(new TinkerArmor()); pulsar.registerPulse(new TinkerWeaponry()); + pulsar.registerPulse(new TinkerGadgets()); pulsar.registerPulse(new TinkerThaumcraft()); pulsar.registerPulse(new TinkerWaila()); pulsar.registerPulse(new TinkerBuildCraft()); @@ -170,6 +173,7 @@ public class TConstruct TConstructRegistry.blockTab = new TConstructCreativeTab("TConstructBlocks"); TConstructRegistry.equipableTab = new TConstructCreativeTab("TConstructEquipables"); TConstructRegistry.weaponryTab = new TConstructCreativeTab("TConstructWeaponry"); + TConstructRegistry.gadgetsTab = new TConstructCreativeTab("TConstructGadgets"); tableCasting = new LiquidCasting(); basinCasting = new LiquidCasting(); @@ -240,6 +244,13 @@ public class TConstruct MinecraftForge.EVENT_BUS.register(new AchievementEvents()); } } + + /** Called on server shutdown to prevent memory leaks */ + @EventHandler + public void serverStopping(FMLServerStoppingEvent event) { + TinkerGadgets.log.info("Cleaning up SlimeBounceHandler data."); + SlimeBounceHandler.BOUNCING_ENTITIES.clear(); + } /* IMC Mod Support */ @EventHandler diff --git a/src/main/java/tconstruct/gadgets/TinkerGadgets.java b/src/main/java/tconstruct/gadgets/TinkerGadgets.java new file mode 100644 index 00000000..74420ee1 --- /dev/null +++ b/src/main/java/tconstruct/gadgets/TinkerGadgets.java @@ -0,0 +1,82 @@ +package tconstruct.gadgets; + +import java.util.Locale; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLPostInitializationEvent; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.registry.GameRegistry; +import mantle.pulsar.pulse.Handler; +import mantle.pulsar.pulse.Pulse; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.oredict.ShapedOreRecipe; +import tconstruct.TConstruct; +import tconstruct.gadgets.item.ItemSlimeBoots; +import tconstruct.gadgets.item.ItemSlimeSling; +import tconstruct.library.SlimeBounceHandler; +import tconstruct.library.TConstructRegistry; + +@Pulse(id = "Tinkers' Gadgets", description = "All the fun toys.") +public class TinkerGadgets { + + public static final String PulseId = "TinkerGadgets"; + public static final Logger log = LogManager.getLogger(PulseId); + + // Gadgets + public static ItemSlimeSling slimeSling; + public static ItemSlimeBoots slimeBoots; + + @Handler + public void preInit(FMLPreInitializationEvent event) { + + SlimeBounceHandler.init(); + slimeSling = registerItem(new ItemSlimeSling(), "slimesling"); + slimeBoots = registerItem(new ItemSlimeBoots(), "slime_boots"); + + } + + @Handler + public void init(FMLInitializationEvent event) { + String ore = "blockSlime"; + + GameRegistry.addRecipe( + new ShapedOreRecipe(new ItemStack(slimeBoots), " ", "s s", "b b", 's', "slimeball", 'b', ore)); + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(slimeSling), "fbf", "s s", " s ", 'f', Items.string, + 's', "slimeball", 'b', ore)); + TConstructRegistry.gadgetsTab.init(new ItemStack(slimeBoots)); + + } + + @Handler + public void postInit(FMLPostInitializationEvent evt) { + + } + + public static String resource(String res) { + return String.format("%s:%s", "tinker", res); + } + + public static ResourceLocation getResource(String res) { + return new ResourceLocation("tinker", res); + } + + public static String prefix(String name) { + return String.format("%s.%s", TConstruct.modID, name.toLowerCase(Locale.US)); + } + + protected static T registerItem(T item, String name) { + if (!name.equals(name.toLowerCase(Locale.US))) { + throw new IllegalArgumentException( + String.format("Unlocalized names need to be all lowercase! Item: %s", name)); + } + item.setUnlocalizedName(prefix(name)); + GameRegistry.registerItem(item, name); + return item; + } +} diff --git a/src/main/java/tconstruct/gadgets/item/ItemSlimeBoots.java b/src/main/java/tconstruct/gadgets/item/ItemSlimeBoots.java new file mode 100644 index 00000000..e7a052cf --- /dev/null +++ b/src/main/java/tconstruct/gadgets/item/ItemSlimeBoots.java @@ -0,0 +1,239 @@ +package tconstruct.gadgets.item; + +import java.util.List; + +import javax.vecmath.Vector3d; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.client.resources.I18n; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemArmor; +import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +import net.minecraftforge.common.ISpecialArmor; +import net.minecraftforge.common.util.EnumHelper; +import net.minecraftforge.event.entity.living.LivingFallEvent; +import tconstruct.library.SlimeBounceHandler; +import tconstruct.library.TConstructRegistry; +import tconstruct.library.armor.ArmorPart; +import tconstruct.tools.entity.FancyEntityItem; + +public class ItemSlimeBoots extends ItemArmor implements ISpecialArmor { + + public static ArmorMaterial SLIME_MATERIAL = EnumHelper.addArmorMaterial("SLIME", 100, new int[] { 0, 0, 0, 0 }, 0); + + public final ArmorPart armorPart; + protected final String textureFolder; + protected final String textureName; + + public ItemSlimeBoots() { + super(SLIME_MATERIAL, 0, 3); + this.setCreativeTab(TConstructRegistry.gadgetsTab); + this.setMaxStackSize(1); + this.setMaxDamage(100); + SLIME_MATERIAL.customCraftingMaterial = Items.slime_ball; + armorPart = ArmorPart.Feet; + textureFolder = "armor"; + textureName = "slime"; + SlimeBounceHandler.registerEvent(this); + } + + @Override + public boolean isValidArmor(ItemStack stack, int armorType1, Entity entity) { + // can be worn as boots + return armorType1 == 3; + } + + // equipping with rightclick + @Override + public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) { + int slot = 1; // 0 = current item, 1 = feet + ItemStack itemstack = playerIn.getEquipmentInSlot(slot); + if (itemstack == null) { + playerIn.setCurrentItemOrArmor(slot, itemStackIn.copy()); + itemStackIn.stackSize--; + } + else { + itemstack = itemstack.copy(); + playerIn.setCurrentItemOrArmor(1, itemStackIn.copy()); + //playerIn.setCurrentItemOrArmor(0, itemstack); + playerIn.entityDropItem(itemstack, 0); + itemStackIn.stackSize--; + } + return itemStackIn; + } + + /** Called when an entity lands to handle the event */ + @SubscribeEvent + // RUBBERY BOUNCY BOUNCERY WOOOOO + public void onFall(LivingFallEvent event) { + EntityLivingBase living = event.entityLiving; + //TinkerGadgets.log.info("Fall event."); + // using fall distance as the event distance could be reduced by jump boost + if (living == null || living.fallDistance <= 2f) { + //TinkerGadgets.log.info("Invalid event."); + return; + } + // can the entity bounce? + if (!SlimeBounceHandler.hasSlimeBoots(living)) { + //TinkerGadgets.log.info("No Boots."); + return; + } + + // reduced fall damage when crouching + if (living.isSneaking()) { + //TinkerGadgets.log.info("Sneaking"); + event.distance = 1; + return; + } + + // thing is wearing slime boots. let's get bouncyyyyy + event.setCanceled(true); + // skip further client processing on players + if (living.worldObj.isRemote) { + //TinkerGadgets.log.info("Client Fall Handler."); + living.playSound("mob.slime.small", 1f, 1f); + SlimeBounceHandler.addBounceHandler(living); + //TConstruct.packetPipeline.sendToServer(new BouncedPacket(living)); + return; + } + + // server players behave differently than non-server players, they have no + // velocity during the event, so we need to reverse engineer it + Vector3d motion = SlimeBounceHandler.getMotion(living); + if (living instanceof EntityPlayerMP) { + // velocity is lost on server players, but we dont have to defer the bounce + double gravity = 0.2353455252; + double time = Math.sqrt(living.fallDistance / gravity); + double velocity = gravity * time; + living.setVelocity(motion.x / 0.95f, velocity, motion.z / 0.95f); + living.velocityChanged = true; + // preserve momentum + SlimeBounceHandler.addBounceHandler(living); + //TinkerGadgets.log.info("Player"); + } + else { + // for non-players, need to defer the bounce + // only slow down half as much when bouncing + living.setVelocity(motion.x / 0.95f, motion.y * -0.9, motion.z / 0.95f); + SlimeBounceHandler.addBounceHandler(living, SlimeBounceHandler.getMotion(living).y); + //TinkerGadgets.log.info("Not Player"); + } + //TinkerGadgets.log.info("Server Fall Handler."); + // update airborn status + living.isAirBorne = true; + living.onGround = false; + event.distance = 0f; + living.playSound("mob.slime.small", 1f, 1f); + } + + @Override + public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot) { + return 2; + } + + @Override + @SideOnly(Side.CLIENT) + public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type) { + return "tinker:textures/armor/" + textureName + "_" + 1 + ".png"; + } + + @SideOnly(Side.CLIENT) + protected IIcon[] modifiers; + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister iconRegister) { + this.itemIcon = iconRegister.registerIcon("tinker:" + textureFolder + "/" + textureName + "_boots"); + + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(ItemStack stack, int renderPass) { + return itemIcon; + } + + @Override + @SideOnly(Side.CLIENT) + public boolean requiresMultipleRenderPasses() { + return false; + } + + @Override + @SideOnly(Side.CLIENT) + public boolean hasEffect(ItemStack par1ItemStack) { + return false; + } + + // ISpecialArmor overrides + @Override + public ArmorProperties getProperties(EntityLivingBase player, ItemStack armor, DamageSource source, double damage, + int slot) { + return new ArmorProperties(0, armor.getItemDamage() / 100, 100); + } + + @Override + public void damageArmor(EntityLivingBase entity, ItemStack armor, DamageSource source, int damage, int slot) { + if (source == DamageSource.fall) { + return; + } + } + + @Override + @SideOnly(Side.CLIENT) + public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List par3List) { + par3List.add(new ItemStack(par1)); + } + + // Vanilla overrides + @Override + public boolean isItemTool(ItemStack par1ItemStack) { + return false; + } + + @Override + public boolean isRepairable() { + return true; + } + + @Override + public int getItemEnchantability() { + return 0; + } + + @Override + public boolean isFull3D() { + return true; + } + + @Override + @SideOnly(Side.CLIENT) + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) { + list.add("Boooounce!"); + list.add("Hold "+(I18n.format(Minecraft.getMinecraft().gameSettings.keyBindSneak.getKeyDescription(), new Object[0]))+" to stop bouncing."); + } + + /* Prevent armor from dying */ + @Override + public boolean hasCustomEntity(ItemStack stack) { + return true; + } + + @Override + public Entity createEntity(World world, Entity location, ItemStack itemstack) { + return new FancyEntityItem(world, location, itemstack); + } +} diff --git a/src/main/java/tconstruct/gadgets/item/ItemSlimeSling.java b/src/main/java/tconstruct/gadgets/item/ItemSlimeSling.java new file mode 100644 index 00000000..ec336200 --- /dev/null +++ b/src/main/java/tconstruct/gadgets/item/ItemSlimeSling.java @@ -0,0 +1,108 @@ +package tconstruct.gadgets.item; + +import java.util.List; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.EnumAction; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.network.play.server.S12PacketEntityVelocity; +import net.minecraft.util.IIcon; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; +import tconstruct.TConstruct; +import tconstruct.gadgets.TinkerGadgets; +import tconstruct.library.SlimeBounceHandler; +import tconstruct.library.TConstructRegistry; +import tconstruct.util.network.MovementUpdatePacket; + +public class ItemSlimeSling extends Item { + + public ItemSlimeSling() { + this.setMaxStackSize(1); + this.setCreativeTab(TConstructRegistry.gadgetsTab); + } + + /** + * Called whenever this item is equipped and the right mouse button is pressed. + * Args: itemStack, world, entityPlayer + */ + @Override + public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) { + playerIn.setItemInUse(itemStackIn, this.getMaxItemUseDuration(itemStackIn)); + return itemStackIn; + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIconFromDamage(int meta) { + return this.itemIcon; + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister iconRegister) { + this.itemIcon = iconRegister.registerIcon("tinker:gadgets/slimesling"); + } + + @Override + public EnumAction getItemUseAction(ItemStack stack) { + return EnumAction.bow; + } + + @Override + public int getMaxItemUseDuration(ItemStack stack) { + return 72000; + } + + // sling logic + @Override + public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int timeLeft) { + // has to be on ground to do something + if (!player.onGround) { + return; + } + + // copy chargeup code from bow \o/ + int i = this.getMaxItemUseDuration(stack) - timeLeft; + float f = i / 20.0F; + f = (f * f + f * 2.0F) / 3.0F; + f *= 4f; + + if (f > 6f) { + f = 6f; + } + + // check if player was targeting a block + MovingObjectPosition mop = getMovingObjectPositionFromPlayer(world, player, false); + + if (mop != null && mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { + // we fling the inverted player look vector + Vec3 vec = player.getLookVec().normalize(); + + player.addVelocity(vec.xCoord * -f, vec.yCoord * -f / 3f, vec.zCoord * -f); + + if (player instanceof EntityPlayerMP) { + EntityPlayerMP playerMP = (EntityPlayerMP) player; + TConstruct.packetPipeline.sendTo(new MovementUpdatePacket(player), playerMP); + playerMP.playerNetServerHandler.sendPacket(new S12PacketEntityVelocity(player)); + } + player.playSound(TinkerGadgets.resource("slimesling"), 1f, 1f); + SlimeBounceHandler.addBounceHandler(player); + // TinkerCommons.potionSlimeBounce.apply(player); + } + } + + @Override + @SideOnly(Side.CLIENT) + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) { + list.add("Aim at a block behind you to get thrown into the air."); + list.add(player.onGround ? "Shoot for the moon!" : "Must be on the ground to use."); + } +} diff --git a/src/main/java/tconstruct/library/SlimeBounceHandler.java b/src/main/java/tconstruct/library/SlimeBounceHandler.java new file mode 100644 index 00000000..2b34187d --- /dev/null +++ b/src/main/java/tconstruct/library/SlimeBounceHandler.java @@ -0,0 +1,288 @@ +package tconstruct.library; + +import java.util.IdentityHashMap; + +import javax.vecmath.Vector3d; + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.util.FakePlayer; +import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; +import tconstruct.gadgets.TinkerGadgets; +import tconstruct.gadgets.item.ItemSlimeBoots; + +/** Logic for entities bouncing */ +public class SlimeBounceHandler { + + public static final float SQRT_2 = sqrt(2.0F); + private static final float[] SIN_TABLE = new float[65536]; + private static final double FRAC_BIAS; + private static final double[] ASINE_TAB; + private static final double[] COS_TAB; + public static final IdentityHashMap BOUNCING_ENTITIES = new IdentityHashMap(); + + static { + for (int i = 0; i < 65536; ++i) { + SIN_TABLE[i] = (float) Math.sin(i * Math.PI * 2.0D / 65536.0D); + } + FRAC_BIAS = Double.longBitsToDouble(4805340802404319232L); + ASINE_TAB = new double[257]; + COS_TAB = new double[257]; + + for (int j = 0; j < 257; ++j) { + double d0 = j / 256.0D; + double d1 = Math.asin(d0); + COS_TAB[j] = Math.cos(d1); + ASINE_TAB[j] = d1; + } + } + + private SlimeBounceHandler() { + TinkerGadgets.log.info("Created instance of Bounce Handler."); + } + + /** Registers event handlers */ + public static void init() { + TinkerGadgets.log.info("Registering Bounce Handler."); + registerEvent(new SlimeBounceHandler()); + } + + /** + * Preserves entity air momentum + * + * @param entity Entity to bounce + */ + public static void addBounceHandler(EntityLivingBase entity) { + addBounceHandler(entity, 0d); + } + + /** + * Causes the entity to bounce, needed because the fall event will reset motion + * afterwards + * + * @param entity Entity to bounce + * @param bounce Bounce amount + */ + public static void addBounceHandler(EntityLivingBase entity, double bounce) { + // no fake players PlayerTick event + if (entity instanceof FakePlayer) { + return; + } + // update bounce info + BounceInfo info = BOUNCING_ENTITIES.get(entity); + if (hasSlimeBoots(entity)) { + if (info == null) { + BOUNCING_ENTITIES.put(entity, new BounceInfo(entity, bounce)); + TinkerGadgets.log.info("Created new BounceInfo for "+entity.getCommandSenderName()); + } else if (bounce != 0) { + TinkerGadgets.log.info("Updating Bounce data?"); + // updated bounce if needed + info.bounce = bounce; + // add one to the tick as there is a 1 tick delay between falling and ticking + // for many entities + info.bounceTick = entity.ticksExisted + 1; + + info.lastMagSq = entity.motionX * entity.motionX + entity.motionZ * entity.motionZ; + info.lastAngle = atan2(entity.motionZ, entity.motionX); + } + } + } + + public static void registerEvent(Object o){ + MinecraftForge.EVENT_BUS.register(o); + FMLCommonHandler.instance().bus().register(o); + } + + /** Called on living tick to preserve momentum and bounce */ + @SubscribeEvent + public void onLivingTick(LivingUpdateEvent event) { + EntityLivingBase entity = event.entityLiving; + if (entity != null) { + BounceInfo info = BOUNCING_ENTITIES.get(entity); + + //TinkerGadgets.log.info("Bounce Data valid? "+(info != null)); + // if we have info for this entity, time to work + if (info != null) { + //TinkerGadgets.log.info("Found Bounce Data in tick handler."); + // if flying, nothing to do + if (entity.isDead || entity.noClip) { + //TinkerGadgets.log.info("Removing Bounce Data."); + BOUNCING_ENTITIES.remove(entity); + return; + } + if (!hasSlimeBoots(entity)) { + //TinkerGadgets.log.info("Removing Bounce Data. No Boots."); + BOUNCING_ENTITIES.remove(entity); + return; + } + + // if its the bounce tick, time to bounce. This is to circumvent the logic that + // resets y motion after landing + if (entity.ticksExisted == info.bounceTick) { + TinkerGadgets.log.info("Bounce Tick?"); + entity.setVelocity(entity.motionX, info.bounce, entity.motionZ); + info.bounceTick = 0; + } + + boolean isInAir = !entity.onGround && !entity.isInWater() && !entity.isOnLadder(); + + //TinkerGadgets.log.info("In Air? "+isInAir); + // preserve motion + if (isInAir && info.lastMagSq > 0) { + // figure out how much motion has reduced + double motionSq = entity.motionX * entity.motionX + entity.motionZ * entity.motionZ; + // if not moving, cancel velocity preserving in 5 ticks + if (motionSq == 0) { + if (info.stopMagTick == 0) { + info.stopMagTick = entity.ticksExisted + 5; + } else if (entity.ticksExisted > info.stopMagTick) { + info.lastMagSq = 0; + } + } else if (motionSq < info.lastMagSq) { + info.stopMagTick = 0; + // preserve 95% of former speed + double boost = Math.sqrt(info.lastMagSq / motionSq) * 0.95f; + if (boost > 1) { + entity.setVelocity(entity.motionX * boost, entity.motionY, entity.motionZ * boost); + entity.isAirBorne = true; + info.lastMagSq = info.lastMagSq * 0.95f * 0.95f; + // play sound if we had a big angle change + double newAngle = atan2(entity.motionZ, entity.motionX); + if (Math.abs(newAngle - info.lastAngle) > 1) { + entity.playSound("mob.slime.small", 1.0f, 1.0f); + } + info.lastAngle = newAngle; + } else { + info.lastMagSq = motionSq; + info.lastAngle = atan2(entity.motionZ, entity.motionX); + } + } + } + //TinkerGadgets.log.info("Did things? 1"); + + // timing the effect out + if (info.wasInAir && !isInAir) { + if (info.endHandler == 0) { + info.endHandler = entity.ticksExisted + 5; + } else if (entity.ticksExisted > info.endHandler) { + //TinkerGadgets.log.info("Removing Bounce Data for "+entity.getCommandSenderName()); + BOUNCING_ENTITIES.remove(entity); + } + } else { + info.endHandler = 0; + info.wasInAir = true; + } + //TinkerGadgets.log.info("Did things? 2"); + } + else { + //TinkerGadgets.log.info("Bad Bounce Data."); + } + } + } + + public static Vector3d getMotion(EntityLivingBase aEntity) { + return new Vector3d(aEntity.motionX, aEntity.motionY, aEntity.motionZ); + } + + public static boolean hasSlimeBoots(EntityLivingBase entity) { + if (entity != null) { + for (int i = 1; i < 5; i++) { + ItemStack aBoots = entity.getEquipmentInSlot(i); + if (aBoots != null && aBoots.getItem() instanceof ItemSlimeBoots) { + //TinkerGadgets.log.info("Found boots in slot "+i); + return true; + } + } + } + return false; + } + + public static float sqrt(float value) { + return (float) Math.sqrt(value); + } + + public static double atan2(double aArg1, double aArg2) { + double d0 = aArg2 * aArg2 + aArg1 * aArg1; + if (Double.isNaN(d0)) { + return Double.NaN; + } else { + boolean flag = aArg1 < 0.0D; + if (flag) { + aArg1 = -aArg1; + } + boolean flag1 = aArg2 < 0.0D; + if (flag1) { + aArg2 = -aArg2; + } + boolean flag2 = aArg1 > aArg2; + if (flag2) { + double d1 = aArg2; + aArg2 = aArg1; + aArg1 = d1; + } + double d9 = fastInvSqrt(d0); + aArg2 = aArg2 * d9; + aArg1 = aArg1 * d9; + double d2 = FRAC_BIAS + aArg1; + int i = (int) Double.doubleToRawLongBits(d2); + double d3 = ASINE_TAB[i]; + double d4 = COS_TAB[i]; + double d5 = d2 - FRAC_BIAS; + double d6 = aArg1 * d4 - aArg2 * d5; + double d7 = (6.0D + d6 * d6) * d6 * 0.16666666666666666D; + double d8 = d3 + d7; + if (flag2) { + d8 = (Math.PI / 2D) - d8; + } + if (flag1) { + d8 = Math.PI - d8; + } + if (flag) { + d8 = -d8; + } + return d8; + } + } + + public static double fastInvSqrt(double aArg) { + double d0 = 0.5D * aArg; + long i = Double.doubleToRawLongBits(aArg); + i = 6910469410427058090L - (i >> 1); + aArg = Double.longBitsToDouble(i); + aArg = aArg * (1.5D - d0 * aArg * aArg); + return aArg; + } + + /** Data class to keep track of bouncing info for an entity */ + private static class BounceInfo { + /** Velocity the entity should have, unused if 0 */ + private double bounce; + /** Time to update the entities velocity */ + private int bounceTick; + /** Tick to stop entity magnitude changes */ + private int stopMagTick; + /** Magnitude of the X/Z motion last tick */ + private double lastMagSq; + /** If true, the entity was in air last tick */ + private boolean wasInAir = false; + /** Time when motion should stop */ + private int endHandler = 0; + /** Last angle of motion, used for sound effects */ + private double lastAngle; + + public BounceInfo(EntityLivingBase entity, double bounce) { + this.bounce = bounce; + if (bounce != 0) { + // add one to the tick as there is a 1 tick delay between falling and ticking + // for many entities + this.bounceTick = entity.ticksExisted + 1; + } else { + this.bounceTick = 0; + } + this.lastMagSq = entity.motionX * entity.motionX + entity.motionZ * entity.motionZ; + } + } +} diff --git a/src/main/java/tconstruct/library/TConstructRegistry.java b/src/main/java/tconstruct/library/TConstructRegistry.java index 0d9e43bb..b65f84a7 100644 --- a/src/main/java/tconstruct/library/TConstructRegistry.java +++ b/src/main/java/tconstruct/library/TConstructRegistry.java @@ -28,6 +28,7 @@ public class TConstructRegistry public static TConstructCreativeTab blockTab; public static TConstructCreativeTab equipableTab; public static TConstructCreativeTab weaponryTab; + public static TConstructCreativeTab gadgetsTab; /* Items */ diff --git a/src/main/resources/assets/tinker/lang/en_US.lang b/src/main/resources/assets/tinker/lang/en_US.lang index 2a92514b..536436d7 100644 --- a/src/main/resources/assets/tinker/lang/en_US.lang +++ b/src/main/resources/assets/tinker/lang/en_US.lang @@ -989,6 +989,9 @@ armor.travelvest.ability=Ability: Swift Swim armor.travelwings.ability=Ability: High Jump armor.travelboots.ability=Ability: High Step +item.TConstruct.slimesling.name=Slimesling +item.TConstruct.slime_boots.name=Slime Boots + tool.reinforced=Reinforced tool.unbreakable=Unbreakable diff --git a/src/main/resources/assets/tinker/sounds.json b/src/main/resources/assets/tinker/sounds.json index af7090a4..28416bed 100644 --- a/src/main/resources/assets/tinker/sounds.json +++ b/src/main/resources/assets/tinker/sounds.json @@ -11,6 +11,12 @@ "little_saw" ] }, + "slimesling": { + "category": "player", + "sounds": [ + "slimesling" + ] + }, "launcher_clank": { "category": "neutral", "sounds": [ diff --git a/src/main/resources/assets/tinker/sounds/slimesling.ogg b/src/main/resources/assets/tinker/sounds/slimesling.ogg new file mode 100644 index 00000000..96bc1431 Binary files /dev/null and b/src/main/resources/assets/tinker/sounds/slimesling.ogg differ diff --git a/src/main/resources/assets/tinker/textures/armor/slime_1.png b/src/main/resources/assets/tinker/textures/armor/slime_1.png new file mode 100644 index 00000000..80c423ee Binary files /dev/null and b/src/main/resources/assets/tinker/textures/armor/slime_1.png differ diff --git a/src/main/resources/assets/tinker/textures/items/armor/slime_boots.png b/src/main/resources/assets/tinker/textures/items/armor/slime_boots.png new file mode 100644 index 00000000..da2011e7 Binary files /dev/null and b/src/main/resources/assets/tinker/textures/items/armor/slime_boots.png differ diff --git a/src/main/resources/assets/tinker/textures/items/gadgets/slimesling.png b/src/main/resources/assets/tinker/textures/items/gadgets/slimesling.png new file mode 100644 index 00000000..53e8fc46 Binary files /dev/null and b/src/main/resources/assets/tinker/textures/items/gadgets/slimesling.png differ