Skip to content

Commit

Permalink
Added redstone control.
Browse files Browse the repository at this point in the history
  • Loading branch information
DrZed committed Feb 5, 2015
1 parent dd9627c commit 5b5e334
Show file tree
Hide file tree
Showing 15 changed files with 285 additions and 44 deletions.
5 changes: 5 additions & 0 deletions src/main/java/HxCKDMS/HxCBlocks/Blocks/BlockBarrier.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockBarrier extends BlockContainer {
Expand All @@ -26,6 +27,10 @@ public TileEntity createNewTileEntity(World world, int metadata) {
return new TileBarrier();
}

@Override
public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) {
return true;
}
@Override
public void onBlockAdded(World world, int x, int y, int z) {
super.onBlockAdded(world, x, y, z);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockSlaughterBlock extends BlockContainer {
Expand All @@ -26,6 +27,11 @@ public TileEntity createNewTileEntity(World world, int metadata) {
return new TileSlaughterBlock();
}

@Override
public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) {
return true;
}

@Override
public void onBlockAdded(World world, int x, int y, int z) {
super.onBlockAdded(world, x, y, z);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import HxCKDMS.HxCBlocks.Registry.CreativeTabHxCBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.world.IBlockAccess;

public class BlockSoulExtractor extends Block {
public BlockSoulExtractor(Material material) {
Expand All @@ -16,4 +17,8 @@ public BlockSoulExtractor(Material material) {
setResistance(1600.0F);
setLightLevel(1);
}
@Override
public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package HxCKDMS.HxCBlocks.Blocks;

import HxCKDMS.HxCBlocks.Reference.References;
import HxCKDMS.HxCBlocks.Registry.CreativeTabHxCBlocks;
import HxCKDMS.HxCBlocks.TileEntities.TileSpawnerAccelerator;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockSpawnerAccelerator extends BlockContainer {

public BlockSpawnerAccelerator(Material material) {
super(material);
setCreativeTab(CreativeTabHxCBlocks.tabHxCBlocks);
setBlockName("Accelerator");
setStepSound(soundTypeMetal);
setBlockTextureName(References.MOD_ID + ":Accelerator");
setHardness(1.0F);
setResistance(1600.0F);
}

@Override
public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) {
return true;
}

@Override
public TileEntity createNewTileEntity(World world, int metadata) {
return new TileSpawnerAccelerator();
}
}
7 changes: 6 additions & 1 deletion src/main/java/HxCKDMS/HxCBlocks/Blocks/BlockVacuum.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockVacuum extends BlockContainer {
Expand All @@ -26,10 +27,14 @@ public TileEntity createNewTileEntity(World world, int metadata) {
return new TileVacuum();
}

@Override
public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) {
return true;
}
@Override
public void onBlockAdded(World world, int x, int y, int z) {
super.onBlockAdded(world, x, y, z);
TileVacuum block = (TileVacuum)world.getTileEntity(x, y, z);
block.AllowUpdate = true; block.modifier = 1;
block.modifier = 1;
}
}
5 changes: 5 additions & 0 deletions src/main/java/HxCKDMS/HxCBlocks/Blocks/BlockXPAbsorber.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockXPAbsorber extends BlockContainer {
Expand All @@ -26,6 +27,10 @@ public TileEntity createNewTileEntity(World world, int metadata) {
return new TileXPAbsorber();
}

@Override
public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) {
return true;
}
@Override
public void onBlockAdded(World world, int x, int y, int z) {
super.onBlockAdded(world, x, y, z);
Expand Down
136 changes: 102 additions & 34 deletions src/main/java/HxCKDMS/HxCBlocks/Events/EventBlockInteract.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@
import HxCKDMS.HxCBlocks.Blocks.BlockSoulExtractor;
import HxCKDMS.HxCBlocks.Items.*;
import HxCKDMS.HxCBlocks.Registry.ModRegistry;
import HxCKDMS.HxCBlocks.TileEntities.TileBarrier;
import HxCKDMS.HxCBlocks.TileEntities.TileSlaughterBlock;
import HxCKDMS.HxCBlocks.TileEntities.TileVacuum;
import HxCKDMS.HxCBlocks.TileEntities.TileXPAbsorber;
import HxCKDMS.HxCBlocks.TileEntities.*;
import HxCKDMS.HxCCore.Handlers.NBTFileIO;
import HxCKDMS.HxCCore.HxCCore;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.block.Block;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemSpade;
import net.minecraft.item.ItemStack;
import net.minecraft.item.*;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
Expand All @@ -34,23 +29,24 @@ public class EventBlockInteract implements EventListener {
int randInt = rand.nextInt(50);
float randfloat = (randInt*.01f);
@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent event){
public void onPlayerInteract(PlayerInteractEvent event) {
Block block = event.world.getBlock(event.x, event.y, event.z);
TileEntity tile = event.world.getTileEntity(event.x, event.y, event.z);
World world = event.world;
EntityPlayer player = event.entityPlayer;
String UUID = player.getUniqueID().toString();
File CustomPlayerData = new File(HxCCore.HxCCoreDir, "HxC-" + UUID + ".dat");
NBTTagCompound nbt = NBTFileIO.getData(CustomPlayerData);
Item item = null; ItemStack stack = null;
if (event.entityPlayer.getHeldItem() != null){
Item item = null;
ItemStack stack = null;
if (event.entityPlayer.getHeldItem() != null) {
item = event.entityPlayer.getHeldItem().getItem();
stack = event.entityPlayer.getHeldItem();
}
/** *
* All data possibly needed gathered above *
* **/
if(block instanceof BlockSoulExtractor && event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)){
if (block instanceof BlockSoulExtractor && event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)) {
float soul = nbt.getFloat("Soul");
if (randfloat <= soul) {
ItemStack fragment = new ItemStack(ModRegistry.SoulFragment);
Expand All @@ -60,34 +56,42 @@ public void onPlayerInteract(PlayerInteractEvent event){
float damagedSoul = soul - randfloat;
NBTFileIO.setFloat(CustomPlayerData, "Soul", damagedSoul);
float hp = player.getHealth();
player.attackEntityFrom(new DamageSource("SoulExtraction"), hp*1000);
if (!world.isRemote) world.spawnEntityInWorld(new EntityItem(world, player.posX, player.posY, player.posZ, fragment));
player.attackEntityFrom(new DamageSource("SoulExtraction"), hp * 1000);
if (!world.isRemote)
world.spawnEntityInWorld(new EntityItem(world, player.posX, player.posY, player.posZ, fragment));
}
} else if (tile instanceof TileXPAbsorber && event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)) {
TileXPAbsorber HxCTile = (TileXPAbsorber)tile;
TileXPAbsorber HxCTile = (TileXPAbsorber) tile;
if (item instanceof ItemSoulBinder) {
HxCTile.BoundPlayer = stack.getTagCompound().getString("Player");
HxCTile.AllowUpdate = true;
if (!player.capabilities.isCreativeMode)player.inventory.decrStackSize(player.inventory.currentItem, 1);
} else if (item instanceof ItemSoulFragment && HxCTile.modifier <=31) {
HxCTile.modifier = (HxCTile.modifier+1);
if (!world.isRemote)player.addChatMessage(new ChatComponentText("\u00A73Range was set to " + HxCTile.modifier));
if (!player.capabilities.isCreativeMode)player.inventory.decrStackSize(player.inventory.currentItem, 1);
if (!player.capabilities.isCreativeMode)
player.inventory.decrStackSize(player.inventory.currentItem, 1);
} else if (item instanceof ItemSoulFragment && HxCTile.modifier <= 31) {
HxCTile.modifier = (HxCTile.modifier + 1);
if (!world.isRemote)
player.addChatMessage(new ChatComponentText("\u00A73Range was set to " + HxCTile.modifier));
if (!player.capabilities.isCreativeMode)
player.inventory.decrStackSize(player.inventory.currentItem, 1);
}
//TODO: Add Configuring Item and gui to block if the item was used on block.
} else if (tile instanceof TileSlaughterBlock && event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)) {
TileSlaughterBlock HxCTile = (TileSlaughterBlock)tile;
if (item instanceof ItemSlaughterCore && HxCTile.modifier <=31) {
HxCTile.modifier = (HxCTile.modifier+1);
if (!world.isRemote)player.addChatMessage(new ChatComponentText("\u00A73Range was set to " + HxCTile.modifier));
if (!player.capabilities.isCreativeMode)player.inventory.decrStackSize(player.inventory.currentItem, 1);
TileSlaughterBlock HxCTile = (TileSlaughterBlock) tile;
if (item instanceof ItemSlaughterCore && HxCTile.modifier <= 31) {
HxCTile.modifier = (HxCTile.modifier + 1);
if (!world.isRemote)
player.addChatMessage(new ChatComponentText("\u00A73Range was set to " + HxCTile.modifier));
if (!player.capabilities.isCreativeMode)
player.inventory.decrStackSize(player.inventory.currentItem, 1);
}
} else if (tile instanceof TileVacuum && event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)) {
TileVacuum HxCTile = (TileVacuum)tile;
if (item instanceof ItemVacuumCore && HxCTile.modifier <=31) {
HxCTile.modifier = (HxCTile.modifier+1);
if (!world.isRemote)player.addChatMessage(new ChatComponentText("\u00A73Range was set to " + HxCTile.modifier));
if (!player.capabilities.isCreativeMode)player.inventory.decrStackSize(player.inventory.currentItem, 1);
TileVacuum HxCTile = (TileVacuum) tile;
if (item instanceof ItemVacuumCore && HxCTile.modifier <= 31) {
HxCTile.modifier = (HxCTile.modifier + 1);
if (!world.isRemote)
player.addChatMessage(new ChatComponentText("\u00A73Range was set to " + HxCTile.modifier));
if (!player.capabilities.isCreativeMode)
player.inventory.decrStackSize(player.inventory.currentItem, 1);
} else if (item instanceof ItemBinder) {
NBTTagCompound dat = stack.getTagCompound();
int[] pb = dat.getIntArray("PB");
Expand All @@ -99,11 +103,75 @@ public void onPlayerInteract(PlayerInteractEvent event){
}
}
} else if (tile instanceof TileBarrier && event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) && item instanceof ItemSpade) {
TileBarrier HxCTile = (TileBarrier)tile;
HxCTile.modifier = (HxCTile.modifier+1);
if (!world.isRemote)player.addChatMessage(new ChatComponentText("\u00A73Range was set to " + HxCTile.modifier));
if (!player.capabilities.isCreativeMode)player.inventory.decrStackSize(player.inventory.currentItem, 1);
} else if (tile instanceof IInventory && event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) && item instanceof ItemBinder) {
TileBarrier HxCTile = (TileBarrier) tile;
HxCTile.modifier = (HxCTile.modifier + 1);
if (!world.isRemote)
player.addChatMessage(new ChatComponentText("\u00A73Range was set to " + HxCTile.modifier));
if (!player.capabilities.isCreativeMode) player.inventory.decrStackSize(player.inventory.currentItem, 1);
} else if (tile instanceof TileSpawnerAccelerator && item instanceof ItemMonsterPlacer) {
TileSpawnerAccelerator HxCTile = (TileSpawnerAccelerator) tile;
ItemMonsterPlacer egg = (ItemMonsterPlacer)item;
int d = egg.getDamage(stack);
switch (d){
case 50: HxCTile.Mob = "Creeper";
break;
case 51: HxCTile.Mob = "Skeleton";
break;
case 52: HxCTile.Mob = "Spider";
break;
case 54: HxCTile.Mob = "Zombie";
break;
case 55: HxCTile.Mob = "Slime";
break;
case 56: HxCTile.Mob = "Ghast";
break;
case 57: HxCTile.Mob = "PigZombie";
break;
case 58: HxCTile.Mob = "Enderman";
break;
case 59: HxCTile.Mob = "CaveSpider";
break;
case 60: HxCTile.Mob = "Silverfish";
break;
case 61: HxCTile.Mob = "Blaze";
break;
case 62: HxCTile.Mob = "LavaSlime";
break;
case 63: HxCTile.Mob = "EnderDragon";
break;
case 64: HxCTile.Mob = "WitherBoss";
break;
case 65: HxCTile.Mob = "Bat";
break;
case 66: HxCTile.Mob = "Witch";
break;
case 91: HxCTile.Mob = "Sheep";
break;
case 92: HxCTile.Mob = "Cow";
break;
case 93: HxCTile.Mob = "Chicken";
break;
case 94: HxCTile.Mob = "Squid";
break;
case 95: HxCTile.Mob = "Wolf";
break;
case 96: HxCTile.Mob = "Mooshroom";
break;
case 97: HxCTile.Mob = "SnowGolem";
break;
case 98: HxCTile.Mob = "Ozelot";
break;
case 99: HxCTile.Mob = "VillagerGolem";
break;
case 100: HxCTile.Mob = "Horse";
break;
case 120: HxCTile.Mob = "Villager";
break;
default: HxCTile.Mob = "Pig";
break;
}

}else if (tile instanceof IInventory && event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) && item instanceof ItemBinder) {
NBTTagCompound dat = stack.getTagCompound();
int[] pb = dat.getIntArray("PB");
int mode = dat.getInteger("Mode");
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/HxCKDMS/HxCBlocks/Events/EventSlaughter.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void Slaughter(int[] coords, World world){
}

protected AxisAlignedBB getAreaBoundingBox(float x, float y, float z, int mod) {
return AxisAlignedBB.getBoundingBox(x - (0.5 + mod), y - (2 + mod), z - (0.5 + mod),
/** Indented because CDO :P **/ (x + 0.5) + mod, (y + 2) + mod, z +(0.5 + mod));
return AxisAlignedBB.getBoundingBox(x - (0.5 + mod), y - (1.5 + mod), z - (0.5 + mod),
/** Indented because CDO :P **/ (x + 0.5) + mod, (y + 1.5) + mod, z +(0.5 + mod));
}
}
3 changes: 3 additions & 0 deletions src/main/java/HxCKDMS/HxCBlocks/Registry/ModRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class ModRegistry {
public static BlockSoulExtractor SoulExtractor = new BlockSoulExtractor(Material.iron);
public static BlockVacuum Vacuum = new BlockVacuum(Material.iron);
public static BlockBarrier Barrier = new BlockBarrier(Material.iron);
public static BlockSpawnerAccelerator Accelerator = new BlockSpawnerAccelerator(Material.iron);
//tab
public static CreativeTabs HxCBlocks = CreativeTabHxCBlocks.tabHxCBlocks;
//items
Expand Down Expand Up @@ -48,6 +49,7 @@ private static void registerBlocks() {
GameRegistry.registerBlock(SoulExtractor, "SoulExtractor");
GameRegistry.registerBlock(Vacuum, "Vacuum");
GameRegistry.registerBlock(Barrier, "Barrier");
GameRegistry.registerBlock(Accelerator, "Accelerator");
}

private static void registerItems() {
Expand All @@ -64,6 +66,7 @@ private static void registerTileEntities() {
GameRegistry.registerTileEntity(TileXPAbsorber.class, "TileXPAbsorber");
GameRegistry.registerTileEntity(TileVacuum.class, "TileVacuum");
GameRegistry.registerTileEntity(TileBarrier.class, "TileBarrier");
GameRegistry.registerTileEntity(TileSpawnerAccelerator.class, "TileSpawnerAccelerator");
}

private static void registerCraftingRecipes() {
Expand Down
Loading

0 comments on commit 5b5e334

Please sign in to comment.