From d0e648f5db3cfb0fea311ae0807513a79fa289f2 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Fri, 12 Sep 2014 13:26:34 -0500 Subject: [PATCH] Added Cube Generator to Unsupported Dev Tools --- core/Registration.java | 2 + debug/BlockCubeGenerator.java | 38 ++++++++++++ debug/TileCubeGenerator.java | 107 ++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 debug/BlockCubeGenerator.java create mode 100644 debug/TileCubeGenerator.java diff --git a/core/Registration.java b/core/Registration.java index 63a391735..7c83f0ff8 100644 --- a/core/Registration.java +++ b/core/Registration.java @@ -91,6 +91,7 @@ import appeng.core.features.registries.entries.CreativeCellHandler; import appeng.core.localization.GuiText; import appeng.core.localization.PlayerMessages; import appeng.debug.BlockChunkloader; +import appeng.debug.BlockCubeGenerator; import appeng.debug.BlockItemGen; import appeng.debug.BlockPhantomNode; import appeng.debug.ToolDebugCard; @@ -420,6 +421,7 @@ public class Registration addFeature( BlockItemGen.class ); addFeature( BlockChunkloader.class ); addFeature( BlockPhantomNode.class ); + addFeature( BlockCubeGenerator.class ); } private AEItemDefinition addFeature(Class c, Object... Args) diff --git a/debug/BlockCubeGenerator.java b/debug/BlockCubeGenerator.java new file mode 100644 index 000000000..06532e859 --- /dev/null +++ b/debug/BlockCubeGenerator.java @@ -0,0 +1,38 @@ +package appeng.debug; + +import java.util.EnumSet; + +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; +import appeng.block.AEBaseBlock; +import appeng.core.features.AEFeature; + +public class BlockCubeGenerator extends AEBaseBlock +{ + + public BlockCubeGenerator() { + super( BlockCubeGenerator.class, Material.iron ); + setfeature( EnumSet.of( AEFeature.UnsupportedDeveloperTools, AEFeature.Creative ) ); + setTileEntiy( TileCubeGenerator.class ); + } + + @Override + public boolean onActivated(World w, int x, int y, int z, + EntityPlayer player, int side, float hitX, float hitY, float hitZ) { + + TileCubeGenerator tcg = getTileEntity(w, x, y, z); + if ( tcg != null ) + tcg.click( player ); + + return true; + } + + @Override + public void registerBlockIcons(IIconRegister iconRegistry) + { + registerNoIcons(); + } + +} diff --git a/debug/TileCubeGenerator.java b/debug/TileCubeGenerator.java new file mode 100644 index 000000000..4d56b169d --- /dev/null +++ b/debug/TileCubeGenerator.java @@ -0,0 +1,107 @@ +package appeng.debug; + + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.core.CommonHelper; +import appeng.tile.AEBaseTile; +import appeng.tile.events.AETileEventHandler; +import appeng.tile.events.TileEventType; +import appeng.util.Platform; + +public class TileCubeGenerator extends AEBaseTile +{ + + int size = 3; + ItemStack is = null; + int countdown = 20 * 10; + EntityPlayer who; + + class TCG extends AETileEventHandler { + + public TCG() { + super(TileEventType.TICK); + } + + @Override + public void Tick() + { + if ( is != null && Platform.isServer() ) + { + countdown--; + + if (countdown % 20 == 0 ) + { + for ( EntityPlayer e : CommonHelper.proxy.getPlayers() ) + { + e.addChatMessage(new ChatComponentText("Spawning in... "+( countdown / 20 ))); + } + } + + if ( countdown <= 0 ) + spawn(); + } + } + + }; + + void spawn() + { + worldObj.setBlock( xCoord, yCoord, zCoord, Platform.air, 0, 3 ); + + Item i = is.getItem(); + int side = ForgeDirection.UP.ordinal(); + + int half = (int) Math.floor( size / 2 ); + + for ( int y = 0; y < size; y++ ) + { + for ( int x = -half; x < half; x++ ) + { + for ( int z = -half; z < half; z++ ) + { + i.onItemUse( is.copy(), who, worldObj, x+xCoord, y+yCoord-1, z+zCoord, side, 0.5f, 0.0f, 0.5f ); + } + } + } + } + + public TileCubeGenerator() { + addNewHandler( new TCG() ); + } + + public void click(EntityPlayer player) + { + if ( Platform.isServer() ) + { + ItemStack hand = player.inventory.getCurrentItem(); + who = player; + + if ( hand == null ) + { + is = null; + + if ( player.isSneaking() ) + size --; + else + size++; + + if ( size < 3 ) + size = 3; + if ( size > 64 ) + size = 64; + + player.addChatMessage( new ChatComponentText("Size: "+size) ); + } + else + { + countdown = 20 * 10; + is = hand; + } + } + } + +}