From 9753e044a46d5b8b95dbec5b308f3aba0b9e17df Mon Sep 17 00:00:00 2001 From: Vasco Lavos Date: Fri, 20 Jun 2014 17:29:47 +0100 Subject: [PATCH 1/2] Spawner mover. --- .../common/core/BotaniaCreativeTab.java | 1 + .../botania/common/item/ItemSpawnerMover.java | 198 +++++++++++++++++- .../vazkii/botania/common/item/ModItems.java | 4 +- .../botania/common/lib/LibItemNames.java | 1 + resources/assets/botania/lang/en_US.lang | 1 + 5 files changed, 198 insertions(+), 7 deletions(-) diff --git a/MODSRC/vazkii/botania/common/core/BotaniaCreativeTab.java b/MODSRC/vazkii/botania/common/core/BotaniaCreativeTab.java index 8694cc686..90705ea2b 100644 --- a/MODSRC/vazkii/botania/common/core/BotaniaCreativeTab.java +++ b/MODSRC/vazkii/botania/common/core/BotaniaCreativeTab.java @@ -66,6 +66,7 @@ public final class BotaniaCreativeTab extends CreativeTabs { addItem(ModItems.openBucket); addItem(ModItems.terraformRod); addItem(ModItems.grassHorn); + addItem(ModItems.spawnerMover); addBlock(ModBlocks.forestDrum); addBlock(ModBlocks.forestEye); diff --git a/MODSRC/vazkii/botania/common/item/ItemSpawnerMover.java b/MODSRC/vazkii/botania/common/item/ItemSpawnerMover.java index fa53254a7..92abb8ae8 100644 --- a/MODSRC/vazkii/botania/common/item/ItemSpawnerMover.java +++ b/MODSRC/vazkii/botania/common/item/ItemSpawnerMover.java @@ -1,5 +1,5 @@ /** - * This class was created by . It's distributed as + * This class was created by . It's distributed as * part of the Botania Mod. Get the Source Code in github: * https://github.com/Vazkii/Botania * @@ -7,13 +7,199 @@ * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) * - * File Created @ [Jun 20, 2014, 4:47:21 PM (GMT)] + * File Created @ [? (GMT)] */ package vazkii.botania.common.item; -// Let this be marked, the day where dylan4ever skipped -// the 1000th commit milestone because he doesn't know -// how to pull before committing. -public class ItemSpawnerMover { +import java.util.List; +import net.minecraft.block.Block; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; +import vazkii.botania.api.BotaniaAPI; +import vazkii.botania.client.core.helper.IconHelper; +import vazkii.botania.common.Botania; +import vazkii.botania.common.lib.LibItemNames; + +public class ItemSpawnerMover extends ItemMod { + + public static final String TAG_SPAWNER = "spawner"; + private static final String TAG_PLACE_DELAY = "placeDelay"; + + IIcon iconNormal, iconSpawner; + + public ItemSpawnerMover() { + setUnlocalizedName(LibItemNames.SPAWNER_MOVER); + setMaxStackSize(1); + } + + @Override + public void registerIcons(IIconRegister par1IconRegister) { + iconNormal = IconHelper.forItem(par1IconRegister, this, 0); + iconSpawner = IconHelper.forItem(par1IconRegister, this, 1); + } + + @Override + public IIcon getIcon(ItemStack stack, int pass) { + return getIconIndex(stack); + } + + @Override + public IIcon getIconIndex(ItemStack par1ItemStack) { + return hasData(par1ItemStack) ? iconSpawner : iconNormal; + } + + public static NBTTagCompound getSpawnerTag(ItemStack stack) { + NBTTagCompound tag = stack.getTagCompound(); + if(tag != null) { + if(tag.hasKey(TAG_SPAWNER)) + return tag.getCompoundTag(TAG_SPAWNER); + if(tag.hasKey("EntityId")) + return tag; + } + + return null; + } + + private static String getEntityId(ItemStack stack) { + NBTTagCompound tag = getSpawnerTag(stack); + if(tag != null) + return tag.getString("EntityId"); + + return null; + } + + public static boolean hasData(ItemStack stack) { + return getEntityId(stack) != null; + } + + private static int getDelay(ItemStack stack) { + NBTTagCompound tag = stack.getTagCompound(); + if(tag != null) + return tag.getInteger(TAG_PLACE_DELAY); + + return 0; + } + + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List infoList, boolean advancedTooltips) { + String id = getEntityId(stack); + if (id != null) + infoList.add(StatCollector.translateToLocal("entity." + id + ".name")); + } + + @Override + public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) { + NBTTagCompound tag = stack.getTagCompound(); + if(tag != null && tag.hasKey(TAG_PLACE_DELAY) && tag.getInteger(TAG_PLACE_DELAY) > 0) + tag.setInteger(TAG_PLACE_DELAY, tag.getInteger(TAG_PLACE_DELAY) - 1); + } + + @Override + public boolean onItemUse(ItemStack itemstack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset) { + if(getEntityId(itemstack) == null) { + if(world.getBlock(x, y, z).equals(Blocks.mob_spawner)) { + TileEntity te = world.getTileEntity(x, y, z); + NBTTagCompound tag = new NBTTagCompound(); + tag.setTag(TAG_SPAWNER, new NBTTagCompound()); + te.writeToNBT(tag.getCompoundTag(TAG_SPAWNER)); + tag.setInteger(TAG_PLACE_DELAY, 20); + itemstack.setTagCompound(tag); + world.setBlockToAir(x, y, z); + player.renderBrokenItemStack(itemstack); + for(int i = 0; i < 50; i++) { + float red = (float) Math.random(); + float green = (float) Math.random(); + float blue = (float) Math.random(); + Botania.proxy.wispFX(world, x + 0.5, y + 0.5, z + 0.5, red, green, blue, (float) Math.random() * 0.1F + 0.05F, (float) (Math.random() - 0.5F) * 0.15F, (float) (Math.random() - 0.5F) * 0.15F, (float) (Math.random() - 0.5F) * 0.15F); + } + return true; + } else return false; + } else { + if(getDelay(itemstack) <= 0 && placeBlock(itemstack, player, world, x, y, z, side, xOffset, yOffset, zOffset)) + return true; + return false; + } + } + + private boolean placeBlock(ItemStack itemstack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset) { + Block block = world.getBlock(x, y, z); + + if(block == Blocks.snow_layer) + side = 1; + else if(block != Blocks.vine && block != Blocks.tallgrass && block != Blocks.deadbush && !block.isReplaceable(world, x, y, z)) { + switch (side) { + case 0: + --y; + break; + case 1: + ++y; + break; + case 2: + --z; + break; + case 3: + ++z; + break; + case 4: + --x; + break; + case 5: + ++x; + break; + } + } + + if(itemstack.stackSize == 0) + return false; + else if(!player.canPlayerEdit(x, y, z, side, itemstack)) + return false; + else if(y == 255 && block.getMaterial().isSolid()) + return false; + else if(world.canPlaceEntityOnSide(Blocks.mob_spawner, x, y, z, false, side, player, itemstack)) { + int meta = block.onBlockPlaced(world, x, y, z, side, xOffset, yOffset, zOffset, 0); + + if(placeBlockAt(itemstack, player, world, x, y, z, side, xOffset, yOffset, zOffset, meta)) { + world.playSoundEffect(x + 0.5F, y + 0.5F, z + 0.5F, block.stepSound.func_150496_b(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F); + player.renderBrokenItemStack(itemstack); + for(int i = 0; i < 60; i++) + Botania.proxy.sparkleFX(world, x + Math.random(), y + Math.random(), z + Math.random(), (float) Math.random(), (float) Math.random(), (float) Math.random(), 0.45F + 0.2F * (float) Math.random(), 6); + + --itemstack.stackSize; + } + + return true; + } + else return false; + } + + private boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) { + if (!world.setBlock(x, y, z, Blocks.mob_spawner, metadata, 3)) + return false; + + Block block = world.getBlock(x, y, z); + if(block.equals(Blocks.mob_spawner)) { + block.onBlockPlacedBy(world, x, y, z, player, stack); + block.onPostBlockPlaced(world, x, y, z, metadata); + TileEntity te = world.getTileEntity(x, y, z); + NBTTagCompound tag = stack.getTagCompound(); + if (tag.hasKey(TAG_SPAWNER)) + tag = tag.getCompoundTag(TAG_SPAWNER); + tag.setInteger("x", x); + tag.setInteger("y", y); + tag.setInteger("z", z); + te.readFromNBT(tag); + world.markBlockForUpdate(x, y, z); + } + + return true; + } } diff --git a/MODSRC/vazkii/botania/common/item/ModItems.java b/MODSRC/vazkii/botania/common/item/ModItems.java index b4ae8926f..f388b81cd 100644 --- a/MODSRC/vazkii/botania/common/item/ModItems.java +++ b/MODSRC/vazkii/botania/common/item/ModItems.java @@ -120,6 +120,7 @@ public final class ModItems { public static Item elementiumSword; public static Item elementiumShears; public static Item openBucket; + public static Item spawnerMover; public static void init() { lexicon = new ItemLexicon(); @@ -184,7 +185,8 @@ public final class ModItems { elementiumSword = new ItemElementiumSword(); elementiumShears = new ItemElementiumShears(); openBucket = new ItemOpenBucket(); - + spawnerMover = new ItemSpawnerMover(); + OreDictionary.registerOre(LibOreDict.LEXICON, lexicon); for(int i = 0; i < 16; i++) { OreDictionary.registerOre(LibOreDict.PETAL[i], new ItemStack(petal, 1, i)); diff --git a/MODSRC/vazkii/botania/common/lib/LibItemNames.java b/MODSRC/vazkii/botania/common/lib/LibItemNames.java index e05af208e..fa45feb5c 100644 --- a/MODSRC/vazkii/botania/common/lib/LibItemNames.java +++ b/MODSRC/vazkii/botania/common/lib/LibItemNames.java @@ -75,6 +75,7 @@ public final class LibItemNames { public static final String ELEMENTIUM_SWORD = "elementiumSword"; public static final String ELEMENTIUM_SHEARS = "elementiumShears"; public static final String OPEN_BUCKET = "openBucket"; + public static final String SPAWNER_MOVER = "spawnerMover"; public static final String[] LENS_NAMES = new String[] { "lensNormal", diff --git a/resources/assets/botania/lang/en_US.lang b/resources/assets/botania/lang/en_US.lang index 5acb7417e..91a6a691f 100644 --- a/resources/assets/botania/lang/en_US.lang +++ b/resources/assets/botania/lang/en_US.lang @@ -497,6 +497,7 @@ item.botania:elementiumAxe.name=Elementium Axe item.botania:elementiumSword.name=Elementium Sword item.botania:elementiumShears.name=Elementium Shears item.botania:openBucket.name=Extrapolated Bucket +item.botania:spawnerMover.name=Life Aggregator # GUI TEXT botania.gui.lexicon.header=Lexica Botania, %s Edition's Index - Pick which category you would like to study: From 989f02d4071e28fe2d56cdba14e2ad93798d5eb4 Mon Sep 17 00:00:00 2001 From: Vasco Lavos Date: Fri, 20 Jun 2014 17:29:58 +0100 Subject: [PATCH 2/2] Update the Credits. --- resources/mcmod.info | 2 +- web/credits.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/resources/mcmod.info b/resources/mcmod.info index bc728358c..185163b5c 100644 --- a/resources/mcmod.info +++ b/resources/mcmod.info @@ -9,7 +9,7 @@ "url": "http://www.vazkii.us", "updateUrl": "", "authorList": ["Vazkii"], - "credits": "Azanor, dylan4ever, Flaxbeard, wiiv, Rorax, Auric245524, MegaManki, mDiyo, Mikeemoo, ChickenBones, cpw", + "credits": "Azanor, dylan4ever, Flaxbeard, wiiv, Rorax, Adubbz, Auric245524, MegaManki, mDiyo, Mikeemoo, ChickenBones, PowerCrystals, cpw", "parent": "", "screenshots": [], "dependencies": [] diff --git a/web/credits.php b/web/credits.php index 789b4e0e0..f84d1a343 100644 --- a/web/credits.php +++ b/web/credits.php @@ -13,6 +13,7 @@ Botania Credits
No project is done with only one member, Botania is no exception, here's the cast of people to thank!

All of my Patrons and Donators for being extremely kind as to support me every month with their own income.
+ Adubbz for the Pixie model and render from Biomes O Plenty.
Auric245524 for the armor textures.
Azanor for letting me use his particles from Thaumcraft and for making the Baubles API.
ChickenBones for the lightning effects from WRCBE.
@@ -24,6 +25,7 @@ MCPBot for always being there for my obfuscation woes.
MegaManki for the mod's logo.
Pokefenn for the Hydroangeas and breaking all the things, every single time.
+ PowerCrystals for the code for the spawner mover.
Rorax for the Pylon model.
ScottWears for hosting my website
The TConstruct and OpenBlocks teams for code snippets I took from their repositories.