From 714626238109e5d0b2c24698bb8964c66f0e123f Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 6 Nov 2018 19:02:56 +0100 Subject: [PATCH] added the shockwave amulet --- .../java/de/ellpeck/naturesaura/Helper.java | 9 +- .../naturesaura/compat/BaublesCompat.java | 13 ++ .../de/ellpeck/naturesaura/items/ItemEye.java | 2 +- .../items/ItemShockwaveCreator.java | 130 ++++++++++++++++++ .../ellpeck/naturesaura/items/ModItems.java | 1 + .../naturesaura/packet/PacketParticles.java | 12 ++ .../assets/naturesaura/lang/en_US.lang | 1 + .../models/item/shockwave_creator.json | 6 + .../textures/items/shockwave_creator.png | Bin 0 -> 679 bytes .../items/shockwave_creator_player.png | Bin 0 -> 515 bytes 10 files changed, 169 insertions(+), 5 deletions(-) create mode 100644 src/main/java/de/ellpeck/naturesaura/items/ItemShockwaveCreator.java create mode 100644 src/main/resources/assets/naturesaura/models/item/shockwave_creator.json create mode 100644 src/main/resources/assets/naturesaura/textures/items/shockwave_creator.png create mode 100644 src/main/resources/assets/naturesaura/textures/items/shockwave_creator_player.png diff --git a/src/main/java/de/ellpeck/naturesaura/Helper.java b/src/main/java/de/ellpeck/naturesaura/Helper.java index 1db7028a..dce7f6d6 100644 --- a/src/main/java/de/ellpeck/naturesaura/Helper.java +++ b/src/main/java/de/ellpeck/naturesaura/Helper.java @@ -177,15 +177,17 @@ public final class Helper { } public static boolean extractAuraFromPlayer(EntityPlayer player, int amount, boolean simulate) { + if (player.capabilities.isCreativeMode) + return true; + if (Compat.baubles) { IItemHandler baubles = BaublesApi.getBaublesHandler(player); for (int i = 0; i < baubles.getSlots(); i++) { ItemStack stack = baubles.getStackInSlot(i); if (!stack.isEmpty() && stack.hasCapability(Capabilities.auraContainer, null)) { amount -= stack.getCapability(Capabilities.auraContainer, null).drainAura(amount, simulate); - if (amount <= 0) { + if (amount <= 0) return true; - } } } } @@ -194,9 +196,8 @@ public final class Helper { ItemStack stack = player.inventory.getStackInSlot(i); if (!stack.isEmpty() && stack.hasCapability(Capabilities.auraContainer, null)) { amount -= stack.getCapability(Capabilities.auraContainer, null).drainAura(amount, simulate); - if (amount <= 0) { + if (amount <= 0) return true; - } } } diff --git a/src/main/java/de/ellpeck/naturesaura/compat/BaublesCompat.java b/src/main/java/de/ellpeck/naturesaura/compat/BaublesCompat.java index ca3b0292..cbe91c6d 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/BaublesCompat.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/BaublesCompat.java @@ -37,6 +37,17 @@ public class BaublesCompat { return true; } }; + private final IBauble shockwaveCreator = new IBauble() { + @Override + public BaubleType getBaubleType(ItemStack itemstack) { + return BaubleType.AMULET; + } + + @Override + public void onWornTick(ItemStack stack, EntityLivingBase player) { + stack.getItem().onUpdate(stack, player.world, player, -1, false); + } + }; @SubscribeEvent public void onCapabilitiesAttach(AttachCapabilitiesEvent event) { @@ -45,6 +56,8 @@ public class BaublesCompat { this.addCap(event, this.eye); } else if (item == ModItems.AURA_CACHE) { this.addCap(event, this.cache); + } else if (item == ModItems.SHOCKWAVE_CREATOR) { + this.addCap(event, this.shockwaveCreator); } } diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemEye.java b/src/main/java/de/ellpeck/naturesaura/items/ItemEye.java index ad7a39a4..f2c79c1d 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ItemEye.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemEye.java @@ -22,7 +22,7 @@ public class ItemEye extends ItemImpl implements ITrinketItem { public void render(ItemStack stack, EntityPlayer player, RenderType type, boolean isHolding) { if (type == RenderType.BODY && !isHolding) { boolean armor = !player.inventory.armorInventory.get(EntityEquipmentSlot.CHEST.getIndex()).isEmpty(); - GlStateManager.translate(0.1F, 0.19F, armor ? -0.195F : -0.13F); + GlStateManager.translate(0.1F, 0.225F, armor ? -0.195F : -0.13F); GlStateManager.scale(0.15F, 0.15F, 0.15F); GlStateManager.rotate(180F, 1F, 0F, 0F); Helper.renderItemInWorld(stack); diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemShockwaveCreator.java b/src/main/java/de/ellpeck/naturesaura/items/ItemShockwaveCreator.java new file mode 100644 index 00000000..b7fe538b --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemShockwaveCreator.java @@ -0,0 +1,130 @@ +package de.ellpeck.naturesaura.items; + +import de.ellpeck.naturesaura.Helper; +import de.ellpeck.naturesaura.NaturesAura; +import de.ellpeck.naturesaura.packet.PacketHandler; +import de.ellpeck.naturesaura.packet.PacketParticles; +import de.ellpeck.naturesaura.renderers.ITrinketItem; +import de.ellpeck.naturesaura.renderers.PlayerLayerTrinkets; +import net.minecraft.block.Block; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumParticleTypes; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import java.util.List; + +public class ItemShockwaveCreator extends ItemImpl implements ITrinketItem { + + @SideOnly(Side.CLIENT) + private static final ResourceLocation RES_WORN = new ResourceLocation(NaturesAura.MOD_ID, "textures/items/shockwave_creator_player.png"); + + public ItemShockwaveCreator() { + super("shockwave_creator"); + this.setMaxStackSize(1); + } + + @Override + public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { + if (worldIn.isRemote || !(entityIn instanceof EntityLivingBase)) + return; + EntityLivingBase living = (EntityLivingBase) entityIn; + if (!living.onGround) { + if (!stack.hasTagCompound()) + stack.setTagCompound(new NBTTagCompound()); + NBTTagCompound compound = stack.getTagCompound(); + if (compound.getBoolean("air")) + return; + + compound.setBoolean("air", true); + compound.setDouble("x", living.posX); + compound.setDouble("y", living.posY); + compound.setDouble("z", living.posZ); + } else { + if (!stack.hasTagCompound()) + return; + NBTTagCompound compound = stack.getTagCompound(); + if (!compound.getBoolean("air")) + return; + + compound.setBoolean("air", false); + + if (!living.isSneaking()) + return; + if (living.getDistanceSq(compound.getDouble("x"), compound.getDouble("y"), compound.getDouble("z")) > 0.75F) + return; + if (living instanceof EntityPlayer && !Helper.extractAuraFromPlayer((EntityPlayer) living, 10, false)) + return; + + int range = 5; + List mobs = worldIn.getEntitiesWithinAABB(EntityLiving.class, new AxisAlignedBB( + living.posX - range, living.posY - 0.5, living.posZ - range, + living.posX + range, living.posY + 0.5, living.posZ + range)); + for (EntityLiving mob : mobs) { + if (mob.isDead || mob == living) + continue; + if (living.getDistanceSq(mob) > range * range) + continue; + if (living instanceof EntityPlayer && !Helper.extractAuraFromPlayer((EntityPlayer) living, 5, false)) + break; + mob.attackEntityFrom(DamageSource.MAGIC, 4F); + } + + BlockPos pos = living.getPosition(); + BlockPos down = pos.down(); + IBlockState downState = worldIn.getBlockState(down); + + if (downState.getMaterial() != Material.AIR) { + SoundType type = downState.getBlock().getSoundType(downState, worldIn, down, null); + worldIn.playSound(null, pos, type.getBreakSound(), SoundCategory.BLOCKS, type.getVolume() * 0.5F, type.getPitch() * 0.8F); + } + if (worldIn instanceof WorldServer) + ((WorldServer) worldIn).spawnParticle(EnumParticleTypes.BLOCK_DUST, + living.posX, living.posY + 0.01F, living.posZ, + 15, 0F, 0F, 0F, 0.15F, Block.getStateId(downState)); + PacketHandler.sendToAllAround(worldIn, pos, 32, + new PacketParticles((float) living.posX, (float) living.posY, (float) living.posZ, 11)); + } + } + + @Override + @SideOnly(Side.CLIENT) + public void render(ItemStack stack, EntityPlayer player, PlayerLayerTrinkets.RenderType type, boolean isHolding) { + if (type == PlayerLayerTrinkets.RenderType.BODY && !isHolding) { + boolean armor = !player.inventory.armorInventory.get(EntityEquipmentSlot.CHEST.getIndex()).isEmpty(); + GlStateManager.translate(-0.1675F, -0.05F, armor ? -0.195F : -0.13F); + GlStateManager.scale(0.021F, 0.021F, 0.021F); + + GlStateManager.pushMatrix(); + GlStateManager.disableLighting(); + GlStateManager.pushAttrib(); + RenderHelper.enableStandardItemLighting(); + Minecraft.getMinecraft().getTextureManager().bindTexture(RES_WORN); + Gui.drawModalRectWithCustomSizedTexture(0, 0, 0, 0, 16, 16, 16, 16); + RenderHelper.disableStandardItemLighting(); + GlStateManager.popAttrib(); + GlStateManager.enableLighting(); + GlStateManager.popMatrix(); + } + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/items/ModItems.java b/src/main/java/de/ellpeck/naturesaura/items/ModItems.java index 778647d5..23eb0e13 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ModItems.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ModItems.java @@ -16,6 +16,7 @@ public final class ModItems { public static final Item ANCIENT_STICK = new ItemImpl("ancient_stick"); public static final Item COLOR_CHANGER = new ItemColorChanger(); public static final Item AURA_CACHE = new ItemAuraCache(); + public static final Item SHOCKWAVE_CREATOR = new ItemShockwaveCreator(); public static final Item.ToolMaterial TOOL_MATERIAL_INFUSED_IRON = EnumHelper.addToolMaterial(NaturesAura.MOD_ID.toUpperCase(Locale.ROOT) + "_INFUSED_IRON", 3, 300, 6.25F, 2.25F, 16); diff --git a/src/main/java/de/ellpeck/naturesaura/packet/PacketParticles.java b/src/main/java/de/ellpeck/naturesaura/packet/PacketParticles.java index 2913f40f..31ccfc54 100644 --- a/src/main/java/de/ellpeck/naturesaura/packet/PacketParticles.java +++ b/src/main/java/de/ellpeck/naturesaura/packet/PacketParticles.java @@ -196,6 +196,18 @@ public class PacketParticles implements IMessage { world.rand.nextGaussian() * 0.015F, world.rand.nextGaussian() * 0.015F, 0xdde7ff, world.rand.nextFloat() + 1F, 30, -0.06F, true, true); + break; + case 11: // Shockwave creator particles + for (int i = 0; i < 360; i += 2) { + double rad = Math.toRadians(i); + NaturesAura.proxy.spawnMagicParticle(world, + message.posX, message.posY + 0.01F, message.posZ, + (float) Math.sin(rad) * 0.65F, + 0F, + (float) Math.cos(rad) * 0.65F, + 0x911b07, 3F, 10, 0F, false, true); + } + break; } } }); diff --git a/src/main/resources/assets/naturesaura/lang/en_US.lang b/src/main/resources/assets/naturesaura/lang/en_US.lang index 517cdd94..badb48be 100644 --- a/src/main/resources/assets/naturesaura/lang/en_US.lang +++ b/src/main/resources/assets/naturesaura/lang/en_US.lang @@ -42,6 +42,7 @@ item.naturesaura.ancient_stick.name=Ancient Wood Rod item.naturesaura.aura_cache.name=Aura Cache item.naturesaura.color_changer.name=Bucket of Infinite Color item.naturesaura.book.name=Book of Natural Aura +item.naturesaura.shockwave_creator.name=Amulet of Wrath container.naturesaura.tree_ritual.name=Ritual of the Forest container.naturesaura.altar.name=Natural Altar Infusion diff --git a/src/main/resources/assets/naturesaura/models/item/shockwave_creator.json b/src/main/resources/assets/naturesaura/models/item/shockwave_creator.json new file mode 100644 index 00000000..905cb892 --- /dev/null +++ b/src/main/resources/assets/naturesaura/models/item/shockwave_creator.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "naturesaura:items/shockwave_creator" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/textures/items/shockwave_creator.png b/src/main/resources/assets/naturesaura/textures/items/shockwave_creator.png new file mode 100644 index 0000000000000000000000000000000000000000..d940f7aeaa540f01fe4b280a9e515f2940671f14 GIT binary patch literal 679 zcmV;Y0$BZtP)004R= z004l4008;_004mL004C`008P>0026e000+nl3&F}00009a7bBm000XS000XS0e@s) zkpKVy7<5HgbW?9;ba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