diff --git a/src/main/java/com/hbm/blocks/ModBlocks.java b/src/main/java/com/hbm/blocks/ModBlocks.java index f69f85497..5f3de7f83 100644 --- a/src/main/java/com/hbm/blocks/ModBlocks.java +++ b/src/main/java/com/hbm/blocks/ModBlocks.java @@ -1243,7 +1243,9 @@ public class ModBlocks { public static Block wand_air; public static Block wand_loot; public static Block wand_jigsaw; - public static Block wand_spawner; + public static Block wand_logic; + + public static Block logic_block; public static Material materialGas = new MaterialGas(); @@ -1978,7 +1980,7 @@ public class ModBlocks { ladder_cobalt = new BlockNTMLadder().setBlockName("ladder_cobalt").setHardness(0.25F).setResistance(2.0F).setCreativeTab(MainRegistry.blockTab).setBlockTextureName(RefStrings.MODID + ":ladder_cobalt"); ladder_steel = new BlockNTMLadder().setBlockName("ladder_steel").setHardness(0.25F).setResistance(2.0F).setCreativeTab(MainRegistry.blockTab).setBlockTextureName(RefStrings.MODID + ":ladder_steel"); ladder_tungsten = new BlockNTMLadder().setBlockName("ladder_tungsten").setHardness(0.25F).setResistance(2.0F).setCreativeTab(MainRegistry.blockTab).setBlockTextureName(RefStrings.MODID + ":ladder_tungsten"); - + trapdoor_steel = new BlockNTMTrapdoor(Material.iron).setBlockName("trapdoor_steel").setHardness(3F).setResistance(8.0F).setStepSound(Block.soundTypeMetal).setCreativeTab(MainRegistry.blockTab).setBlockTextureName(RefStrings.MODID + ":trapdoor_steel"); barrel_plastic = new BlockFluidBarrel(Material.iron, 12000).setBlockName("barrel_plastic").setStepSound(Block.soundTypeStone).setHardness(2.0F).setResistance(5.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":barrel_plastic"); @@ -2397,7 +2399,9 @@ public class ModBlocks { wand_air = new BlockWand(Blocks.air).setBlockName("wand_air").setBlockTextureName(RefStrings.MODID + ":wand_air"); wand_loot = new BlockWandLoot().setBlockName("wand_loot").setBlockTextureName(RefStrings.MODID + ":wand_loot"); wand_jigsaw = new BlockWandJigsaw().setBlockName("wand_jigsaw").setBlockTextureName(RefStrings.MODID + ":wand_jigsaw"); - wand_spawner = new BlockWandSpawner().setBlockName("wand_spawner").setBlockTextureName(RefStrings.MODID + ":wand_spawner"); + wand_logic = new BlockWandLogic().setBlockName("wand_logic").setBlockTextureName(RefStrings.MODID + ":wand_logic"); + + logic_block = new LogicBlock().setBlockName("logic_block").setBlockTextureName(RefStrings.MODID + ":logic_block"); } @@ -3545,7 +3549,9 @@ public class ModBlocks { register(wand_air); register(wand_loot); register(wand_jigsaw); - register(wand_spawner); + register(wand_logic); + + register(logic_block); } private static void register(Block b) { diff --git a/src/main/java/com/hbm/blocks/generic/BlockWandSpawner.java b/src/main/java/com/hbm/blocks/generic/BlockWandLogic.java similarity index 74% rename from src/main/java/com/hbm/blocks/generic/BlockWandSpawner.java rename to src/main/java/com/hbm/blocks/generic/BlockWandLogic.java index b6c042838..01d8df298 100644 --- a/src/main/java/com/hbm/blocks/generic/BlockWandSpawner.java +++ b/src/main/java/com/hbm/blocks/generic/BlockWandLogic.java @@ -13,10 +13,10 @@ import com.hbm.main.MainRegistry; import com.hbm.tileentity.TileEntityLoadedBase; import com.hbm.util.BufferUtil; import com.hbm.util.i18n.I18nUtil; +import com.hbm.world.gen.util.LogicBlockActions; import com.hbm.world.gen.INBTTileEntityTransformable; -import com.hbm.world.gen.util.DungeonSpawnerActions; -import com.hbm.world.gen.util.DungeonSpawnerConditions; -import com.hbm.world.gen.util.DungeonSpawnerInteractions; +import com.hbm.world.gen.util.LogicBlockConditions; +import com.hbm.world.gen.util.LogicBlockInteractions; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -43,19 +43,19 @@ import net.minecraftforge.common.util.ForgeDirection; import java.util.ArrayList; import java.util.List; -public class BlockWandSpawner extends BlockContainer implements ILookOverlay, IToolable, ITooltipProvider, IBlockSideRotation, IBomb { +public class BlockWandLogic extends BlockContainer implements ILookOverlay, IToolable, ITooltipProvider, IBlockSideRotation, IBomb { @SideOnly(Side.CLIENT) protected IIcon iconTop; - public BlockWandSpawner() { + public BlockWandLogic() { super(Material.iron); } @Override @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister iconRegister) { - this.blockIcon = iconRegister.registerIcon(RefStrings.MODID + ":wand_spawner"); - this.iconTop = iconRegister.registerIcon(RefStrings.MODID + ":wand_spawner_top"); + this.blockIcon = iconRegister.registerIcon(RefStrings.MODID + ":wand_logic"); + this.iconTop = iconRegister.registerIcon(RefStrings.MODID + ":wand_logic_top"); } @Override @@ -92,8 +92,8 @@ public class BlockWandSpawner extends BlockContainer implements ILookOverlay, IT case 3: dir = ForgeDirection.EAST; break; } TileEntity te = world.getTileEntity(x, y, z); - if(te instanceof TileEntityWandSpawner) - ((TileEntityWandSpawner)te).placedRotation = dir.ordinal(); + if(te instanceof TileEntityWandLogic) + ((TileEntityWandLogic)te).placedRotation = dir.ordinal(); } @Override @@ -109,10 +109,10 @@ public class BlockWandSpawner extends BlockContainer implements ILookOverlay, IT TileEntity tile = world.getTileEntity(x, y, z); - if(tile instanceof TileEntityWandSpawner){ - TileEntityWandSpawner spawner = (TileEntityWandSpawner) tile; - spawner.disguise = block; - spawner.disguiseMeta = stack.getItemDamage() & 15; + if(tile instanceof TileEntityWandLogic){ + TileEntityWandLogic logic = (TileEntityWandLogic) tile; + logic.disguise = block; + logic.disguiseMeta = stack.getItemDamage() & 15; return true; } } @@ -124,38 +124,38 @@ public class BlockWandSpawner extends BlockContainer implements ILookOverlay, IT public boolean onScrew(World world, EntityPlayer player, int x, int y, int z, int side, float fX, float fY, float fZ, ToolType tool) { TileEntity te = world.getTileEntity(x, y, z); - if(!(te instanceof TileEntityWandSpawner)) return false; + if(!(te instanceof TileEntityWandLogic)) return false; - TileEntityWandSpawner spawner = (TileEntityWandSpawner) te; + TileEntityWandLogic logic = (TileEntityWandLogic) te; switch(tool) { case SCREWDRIVER: - List actionNames = DungeonSpawnerActions.getActionNames(); - int indexA = actionNames.indexOf(spawner.actionID); + List actionNames = LogicBlockActions.getActionNames(); + int indexA = actionNames.indexOf(logic.actionID); indexA += player.isSneaking() ? -1 : 1; indexA = MathHelper.clamp_int(indexA, 0, actionNames.size() - 1); - spawner.actionID = actionNames.get(indexA); + logic.actionID = actionNames.get(indexA); return true; case DEFUSER: - List conditionNames = DungeonSpawnerConditions.getConditionNames(); - int indexC = conditionNames.indexOf(spawner.conditionID); + List conditionNames = LogicBlockConditions.getConditionNames(); + int indexC = conditionNames.indexOf(logic.conditionID); indexC += player.isSneaking() ? -1 : 1; indexC = MathHelper.clamp_int(indexC, 0, conditionNames.size() - 1); - spawner.conditionID = conditionNames.get(indexC); + logic.conditionID = conditionNames.get(indexC); return true; case HAND_DRILL: - List interactionNames = DungeonSpawnerInteractions.getInteractionNames(); - int indexI = interactionNames.indexOf(spawner.interactionID); + List interactionNames = LogicBlockInteractions.getInteractionNames(); + int indexI = interactionNames.indexOf(logic.interactionID); indexI += player.isSneaking() ? -1 : 1; indexI = MathHelper.clamp_int(indexI, 0, interactionNames.size() - 1); - spawner.interactionID = interactionNames.get(indexI); + logic.interactionID = interactionNames.get(indexI); return true; @@ -167,19 +167,19 @@ public class BlockWandSpawner extends BlockContainer implements ILookOverlay, IT public void printHook(RenderGameOverlayEvent.Pre event, World world, int x, int y, int z) { TileEntity te = world.getTileEntity(x, y, z); - if(!(te instanceof TileEntityWandSpawner)) return; + if(!(te instanceof TileEntityWandLogic)) return; - TileEntityWandSpawner spawner = (TileEntityWandSpawner) te; + TileEntityWandLogic logic = (TileEntityWandLogic) te; List text = new ArrayList<>(); - text.add("Action: " + spawner.actionID); - text.add("Condition: " + spawner.conditionID); - text.add("Interaction: " + (spawner.interactionID != null ? spawner.interactionID : "None")); + text.add("Action: " + logic.actionID); + text.add("Condition: " + logic.conditionID); + text.add("Interaction: " + (logic.interactionID != null ? logic.interactionID : "None")); String block; - if(spawner.disguise != null && spawner.disguise != Blocks.air) - block = I18nUtil.resolveKey(spawner.disguise.getUnlocalizedName() + ".name"); + if(logic.disguise != null && logic.disguise != Blocks.air) + block = I18nUtil.resolveKey(logic.disguise.getUnlocalizedName() + ".name"); else block = "None"; @@ -198,21 +198,21 @@ public class BlockWandSpawner extends BlockContainer implements ILookOverlay, IT @Override public TileEntity createNewTileEntity(World worldIn, int meta) { - return new TileEntityWandSpawner(); + return new TileEntityWandLogic(); } @Override public BombReturnCode explode(World world, int x, int y, int z) { TileEntity te = world.getTileEntity(x, y, z); - if(!(te instanceof TileEntityWandSpawner)) return null; + if(!(te instanceof TileEntityWandLogic)) return null; - ((TileEntityWandSpawner) te).triggerReplace = true; + ((TileEntityWandLogic) te).triggerReplace = true; return BombReturnCode.TRIGGERED; } - public static class TileEntityWandSpawner extends TileEntityLoadedBase implements INBTTileEntityTransformable, ICopiable { + public static class TileEntityWandLogic extends TileEntityLoadedBase implements INBTTileEntityTransformable, ICopiable { private boolean triggerReplace; public int placedRotation; @@ -220,8 +220,8 @@ public class BlockWandSpawner extends BlockContainer implements ILookOverlay, IT Block disguise; int disguiseMeta = -1; - public String actionID = "PHASE_ABERRATOR"; - public String conditionID = "EMPTY"; + public String actionID = "FODDER_WAVE"; + public String conditionID = "PLAYER_CUBE_5"; public String interactionID; @Override @@ -237,28 +237,28 @@ public class BlockWandSpawner extends BlockContainer implements ILookOverlay, IT } private void replace() { - if (!(worldObj.getBlock(xCoord, yCoord, zCoord) instanceof BlockWandSpawner)) { - MainRegistry.logger.warn("Somehow the block at: " + xCoord + ", " + yCoord + ", " + zCoord + " isn't a dungeon spawner block but we're doing a TE update as if it is, cancelling!"); + if (!(worldObj.getBlock(xCoord, yCoord, zCoord) instanceof BlockWandLogic)) { + MainRegistry.logger.warn("Somehow the block at: " + xCoord + ", " + yCoord + ", " + zCoord + " isn't a logic block but we're doing a TE update as if it is, cancelling!"); return; } - worldObj.setBlock(xCoord,yCoord,zCoord, ModBlocks.dungeon_spawner); + worldObj.setBlock(xCoord,yCoord,zCoord, ModBlocks.logic_block); TileEntity te = worldObj.getTileEntity(xCoord, yCoord, zCoord); if(te == null || te instanceof BlockWandLoot.TileEntityWandLoot) { - MainRegistry.logger.warn("TE for dungeon spawner set incorrectly at: " + xCoord + ", " + yCoord + ", " + zCoord + ". If you're using some sort of world generation mod, report it to the author!"); - te = ModBlocks.wand_spawner.createTileEntity(worldObj, 0); + MainRegistry.logger.warn("TE for logic block set incorrectly at: " + xCoord + ", " + yCoord + ", " + zCoord + ". If you're using some sort of world generation mod, report it to the author!"); + te = ModBlocks.wand_logic.createTileEntity(worldObj, 0); worldObj.setTileEntity(xCoord, yCoord, zCoord, te); } - if(te instanceof DungeonSpawner.TileEntityDungeonSpawner){ - DungeonSpawner.TileEntityDungeonSpawner spawner = (DungeonSpawner.TileEntityDungeonSpawner) te; - spawner.actionID = actionID; - spawner.conditionID = conditionID; - spawner.interactionID = interactionID; - spawner.direction = ForgeDirection.getOrientation(placedRotation); - spawner.disguise = disguise; - spawner.disguiseMeta = disguiseMeta; + if(te instanceof LogicBlock.TileEntityLogicBlock){ + LogicBlock.TileEntityLogicBlock logic = (LogicBlock.TileEntityLogicBlock) te; + logic.actionID = actionID; + logic.conditionID = conditionID; + logic.interactionID = interactionID; + logic.direction = ForgeDirection.getOrientation(placedRotation); + logic.disguise = disguise; + logic.disguiseMeta = disguiseMeta; } } diff --git a/src/main/java/com/hbm/blocks/generic/DungeonSpawner.java b/src/main/java/com/hbm/blocks/generic/DungeonSpawner.java index 52dbb6099..4a6fc10d8 100644 --- a/src/main/java/com/hbm/blocks/generic/DungeonSpawner.java +++ b/src/main/java/com/hbm/blocks/generic/DungeonSpawner.java @@ -7,32 +7,18 @@ import com.hbm.blocks.generic.BlockSkeletonHolder.TileEntitySkeletonHolder; import com.hbm.entity.mob.EntityUndeadSoldier; import com.hbm.items.ItemEnums.EnumSecretType; import com.hbm.items.ModItems; -import com.hbm.util.BufferUtil; -import com.hbm.world.gen.util.DungeonSpawnerActions; -import com.hbm.world.gen.util.DungeonSpawnerConditions; +import com.hbm.util.EnumUtil; import com.hbm.util.Vec3NT; -import com.hbm.world.gen.util.DungeonSpawnerInteractions; -import cpw.mods.fml.common.registry.GameRegistry; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import io.netty.buffer.ByteBuf; -import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.Packet; -import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.IIcon; -import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; public class DungeonSpawner extends BlockContainer { @@ -44,76 +30,19 @@ public class DungeonSpawner extends BlockContainer { public TileEntity createNewTileEntity(World world, int meta) { return new TileEntityDungeonSpawner(); } - - @Override - @SideOnly(Side.CLIENT) - public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) { - TileEntity tile = world.getTileEntity(x, y, z); - - if(tile instanceof TileEntityDungeonSpawner){ - TileEntityDungeonSpawner spawner = (TileEntityDungeonSpawner) tile; - if(spawner.disguise != null){ - return spawner.disguise.getIcon(side, spawner.disguiseMeta); - } - } - - return super.getIcon(world, x, y, z, side); - } - - @Override - public boolean onBlockActivated(World worldIn, int x, int y, int z, EntityPlayer player, int side, float subX, float subY, float subZ) { - TileEntity te = worldIn.getTileEntity(x, y, z); - if(te instanceof TileEntityDungeonSpawner && ((TileEntityDungeonSpawner) te).interaction != null) { - ((TileEntityDungeonSpawner) te).interaction.accept(new Object[]{worldIn, te, x, y, z, player, side, subX, subY, subZ}); - return true; - } - - return super.onBlockActivated(worldIn, x, y, z, player, side, subX, subY, subZ); - } - + public static class TileEntityDungeonSpawner extends TileEntity { - - //phase is incremented per condition check, timer counts since last condition check by default + public int phase = 0; public int timer = 0; - - public Block disguise; - public int disguiseMeta; - - /**Actions always get called before conditions, use the phase and timer variables in order to control behavior via conditions*/ - public String conditionID = "ABERRATOR"; - public String actionID = "ABERRATOR"; - /**Interactions are called on right click, and passes on the parameters of the right click to consumer*/ - public String interactionID; - - public Function condition; - public Consumer action; - /**Consists of world instance, TileEntity instance, three ints for coordinates, one int for block side, and player instance, in that order **/ - public Consumer interaction; - - public EntityPlayer player; - - public ForgeDirection direction = ForgeDirection.UNKNOWN; + public EnumSpawnerType type = EnumSpawnerType.ABERRATOR; + @Override public void updateEntity() { - + if(!worldObj.isRemote) { - if(action == null){ - action = DungeonSpawnerActions.actions.get(actionID); - } - if(condition == null){ - condition = DungeonSpawnerConditions.conditions.get(conditionID); - } - if(interaction == null && interactionID != null){ - interaction = DungeonSpawnerInteractions.interactions.get(interactionID); - } - - if(action == null || condition == null){ - worldObj.setBlock(xCoord,yCoord,zCoord, Blocks.air); - return; - } - action.accept(this); - if(condition.apply(this)) { + type.phase.accept(this); + if(type.phaseCondition.apply(this)) { phase++; timer = 0; } else { @@ -126,47 +55,83 @@ public class DungeonSpawner extends BlockContainer { public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); nbt.setInteger("phase", phase); - - nbt.setString("actionID", actionID); - nbt.setString("conditionID", conditionID); - if(interactionID != null) - nbt.setString("interactionID", interactionID); - - nbt.setInteger("direction", direction.ordinal()); - if(disguise != null){ - nbt.setInteger("disguiseMeta", disguiseMeta); - nbt.setString("disguise", GameRegistry.findUniqueIdentifierFor(disguise).toString()); - } + nbt.setByte("type", (byte) type.ordinal()); } @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); this.phase = nbt.getInteger("phase"); - - this.actionID = nbt.getString("actionID"); - this.conditionID = nbt.getString("conditionID"); - if(nbt.hasKey("interactionID")) this.interactionID = nbt.getString("interactionID"); - - this.direction = ForgeDirection.getOrientation(nbt.getInteger("direction")); - - if(nbt.hasKey("disguise")){ - disguiseMeta = nbt.getInteger("disguiseMeta"); - disguise = Block.getBlockFromName(nbt.getString("disguise")); - } - } - - @Override - public Packet getDescriptionPacket() { - NBTTagCompound nbt = new NBTTagCompound(); - this.writeToNBT(nbt); - return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, nbt); - } - - @Override - public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { - this.readFromNBT(pkt.func_148857_g()); + this.type = EnumUtil.grabEnumSafely(EnumSpawnerType.class, nbt.getByte("type")); } } + + public static enum EnumSpawnerType { + + ABERRATOR(CON_ABERRATOR, PHASE_ABERRATOR); + public Function phaseCondition; + public Consumer phase; + + private EnumSpawnerType(Function con, Consumer ph) { + this.phaseCondition = con; + this.phase = ph; + } + } + + public static Function CON_ABERRATOR = (tile) -> { + World world = tile.getWorldObj(); + if(world.difficultySetting.ordinal() == 0) return false; + int x = tile.xCoord; + int y = tile.yCoord; + int z = tile.zCoord; + if(tile.phase == 0) { + if(world.getTotalWorldTime() % 20 != 0) return false; + return !world.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y - 2, z + 1).expand(20, 10, 20)).isEmpty(); + } + if(tile.phase < 3) { + if(world.getTotalWorldTime() % 20 != 0 || tile.timer < 60) return false; + return world.getEntitiesWithinAABB(EntityUndeadSoldier.class, AxisAlignedBB.getBoundingBox(x, y, z, x - 2, y + 1, z + 1).expand(50, 20, 50)).isEmpty(); + } + return false; + }; + + public static Consumer PHASE_ABERRATOR = (tile) -> { + World world = tile.getWorldObj(); + int x = tile.xCoord; + int y = tile.yCoord; + int z = tile.zCoord; + if(tile.phase == 1 || tile.phase == 2) { + if(tile.timer == 0) { + Vec3NT vec = new Vec3NT(10, 0, 0); + for(int i = 0; i < 10; i++) { + EntityUndeadSoldier mob = new EntityUndeadSoldier(world); + for(int j = 0; j < 7; j++) { + mob.setPositionAndRotation(x + 0.5 + vec.xCoord, y - 5, z + 0.5 + vec.zCoord, i * 36F, 0); + if(mob.getCanSpawnHere()) { + mob.onSpawnWithEgg(null); + world.spawnEntityInWorld(mob); + break; + } + } + + vec.rotateAroundYDeg(36D); + } + } + } + if(tile.phase > 2) { + TileEntity te = world.getTileEntity(x, y + 18, z); + if(te instanceof TileEntitySkeletonHolder) { + TileEntitySkeletonHolder skeleton = (TileEntitySkeletonHolder) te; + if(world.rand.nextInt(5) == 0) { + skeleton.item = new ItemStack(ModItems.item_secret, 1, EnumSecretType.ABERRATOR.ordinal()); + } else { + skeleton.item = new ItemStack(ModItems.clay_tablet, 1, 1); + } + skeleton.markDirty(); + world.markBlockForUpdate(x, y + 18, z); + } + world.setBlock(x, y, z, Blocks.obsidian); + } + }; } diff --git a/src/main/java/com/hbm/blocks/generic/LogicBlock.java b/src/main/java/com/hbm/blocks/generic/LogicBlock.java new file mode 100644 index 000000000..462755811 --- /dev/null +++ b/src/main/java/com/hbm/blocks/generic/LogicBlock.java @@ -0,0 +1,162 @@ +package com.hbm.blocks.generic; + +import com.hbm.world.gen.util.LogicBlockActions; +import com.hbm.world.gen.util.LogicBlockConditions; +import com.hbm.world.gen.util.LogicBlockInteractions; +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.Block; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.Material; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +import java.util.function.Consumer; +import java.util.function.Function; + +public class LogicBlock extends BlockContainer { + + public LogicBlock() { + super(Material.rock); + } + + @Override + public TileEntity createNewTileEntity(World world, int meta) { + return new LogicBlock.TileEntityLogicBlock(); + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) { + TileEntity tile = world.getTileEntity(x, y, z); + + if(tile instanceof LogicBlock.TileEntityLogicBlock){ + LogicBlock.TileEntityLogicBlock logicBlock = (LogicBlock.TileEntityLogicBlock) tile; + if(logicBlock.disguise != null){ + return logicBlock.disguise.getIcon(side, logicBlock.disguiseMeta); + } + } + + return super.getIcon(world, x, y, z, side); + } + + @Override + public boolean onBlockActivated(World worldIn, int x, int y, int z, EntityPlayer player, int side, float subX, float subY, float subZ) { + TileEntity te = worldIn.getTileEntity(x, y, z); + if(te instanceof LogicBlock.TileEntityLogicBlock && ((LogicBlock.TileEntityLogicBlock) te).interaction != null) { + ((LogicBlock.TileEntityLogicBlock) te).interaction.accept(new Object[]{worldIn, te, x, y, z, player, side, subX, subY, subZ}); + return true; + } + + return super.onBlockActivated(worldIn, x, y, z, player, side, subX, subY, subZ); + } + + public static class TileEntityLogicBlock extends TileEntity { + + //phase is incremented per condition check, timer counts since last condition check by default + public int phase = 0; + public int timer = 0; + + public Block disguise; + public int disguiseMeta; + + /**Actions always get called before conditions, use the phase and timer variables in order to control behavior via conditions*/ + public String conditionID = "PLAYER_CUBE_5"; + public String actionID = "FODDER_WAVE"; + /**Interactions are called on right click, and passes on the parameters of the right click to consumer*/ + public String interactionID; + + public Function condition; + public Consumer action; + /**Consists of world instance, TileEntity instance, three ints for coordinates, one int for block side, and player instance, in that order **/ + public Consumer interaction; + + public EntityPlayer player; + + public ForgeDirection direction = ForgeDirection.UNKNOWN; + @Override + public void updateEntity() { + + if(!worldObj.isRemote) { + if(action == null){ + action = LogicBlockActions.actions.get(actionID); + } + if(condition == null){ + condition = LogicBlockConditions.conditions.get(conditionID); + } + if(interaction == null && interactionID != null){ + interaction = LogicBlockInteractions.interactions.get(interactionID); + } + + if(action == null || condition == null){ + worldObj.setBlock(xCoord,yCoord,zCoord, Blocks.air); + return; + } + action.accept(this); + if(condition.apply(this)) { + phase++; + timer = 0; + } else { + timer++; + } + } + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + nbt.setInteger("phase", phase); + + nbt.setString("actionID", actionID); + nbt.setString("conditionID", conditionID); + if(interactionID != null) + nbt.setString("interactionID", interactionID); + + nbt.setInteger("direction", direction.ordinal()); + if(disguise != null){ + nbt.setInteger("disguiseMeta", disguiseMeta); + nbt.setString("disguise", GameRegistry.findUniqueIdentifierFor(disguise).toString()); + } + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + this.phase = nbt.getInteger("phase"); + + this.actionID = nbt.getString("actionID"); + this.conditionID = nbt.getString("conditionID"); + if(nbt.hasKey("interactionID")) this.interactionID = nbt.getString("interactionID"); + + this.direction = ForgeDirection.getOrientation(nbt.getInteger("direction")); + + if(nbt.hasKey("disguise")){ + disguiseMeta = nbt.getInteger("disguiseMeta"); + disguise = Block.getBlockFromName(nbt.getString("disguise")); + } + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound nbt = new NBTTagCompound(); + this.writeToNBT(nbt); + return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, nbt); + } + + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + this.readFromNBT(pkt.func_148857_g()); + } + } + +} diff --git a/src/main/java/com/hbm/tileentity/TileEntityDoorGeneric.java b/src/main/java/com/hbm/tileentity/TileEntityDoorGeneric.java index 9b8751d05..e460bc08b 100644 --- a/src/main/java/com/hbm/tileentity/TileEntityDoorGeneric.java +++ b/src/main/java/com/hbm/tileentity/TileEntityDoorGeneric.java @@ -21,7 +21,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.AxisAlignedBB; import net.minecraftforge.common.util.ForgeDirection; -public class TileEntityDoorGeneric extends TileEntityLockableBase { +public class TileEntityDoorGeneric extends TileEntityLockableBase { //0: closed, 1: open, 2: closing, 3: opening public byte state = 0; @@ -318,6 +318,15 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase { return true; } + /**Useful for logic block interactions, as a way to close/open doors**/ + public void open(){ + if(state == 0) state = 3; + } + + public void close() { + if(state == 1) state = 2; + } + @Override public AxisAlignedBB getRenderBoundingBox() { return INFINITE_EXTENT_AABB; @@ -404,4 +413,4 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase { } } -} \ No newline at end of file +} diff --git a/src/main/java/com/hbm/tileentity/TileMappings.java b/src/main/java/com/hbm/tileentity/TileMappings.java index f688059be..1c938ab18 100644 --- a/src/main/java/com/hbm/tileentity/TileMappings.java +++ b/src/main/java/com/hbm/tileentity/TileMappings.java @@ -19,8 +19,9 @@ import com.hbm.blocks.generic.BlockSnowglobe.TileEntitySnowglobe; import com.hbm.blocks.generic.BlockSupplyCrate.TileEntitySupplyCrate; import com.hbm.blocks.generic.BlockWandJigsaw.TileEntityWandJigsaw; import com.hbm.blocks.generic.BlockWandLoot.TileEntityWandLoot; -import com.hbm.blocks.generic.BlockWandSpawner.TileEntityWandSpawner; +import com.hbm.blocks.generic.BlockWandLogic.TileEntityWandLogic; import com.hbm.blocks.generic.DungeonSpawner.TileEntityDungeonSpawner; +import com.hbm.blocks.generic.LogicBlock; import com.hbm.blocks.generic.PartEmitter.TileEntityPartEmitter; import com.hbm.blocks.machine.BlockICF.TileEntityBlockICF; import com.hbm.blocks.machine.BlockPWR.TileEntityBlockPWR; @@ -209,6 +210,7 @@ public class TileMappings { put(TileEntityPedestal.class, "tileentity_ntm_pedestal"); put(TileEntitySkeletonHolder.class, "tileentity_ntm_skeleton"); put(TileEntityDungeonSpawner.class, "tileentity_ntm_dungeon_spawner"); + put(LogicBlock.TileEntityLogicBlock.class, "tileentity_ntm_logic_block"); put(TileEntityBobble.class, "tileentity_ntm_bobblehead"); put(TileEntitySnowglobe.class, "tileentity_ntm_snowglobe"); put(TileEntityPlushie.class, "tileentity_ntm_plushie"); @@ -237,7 +239,7 @@ public class TileMappings { put(TileEntityWandLoot.class, "tileentity_wand_loot"); put(TileEntityWandJigsaw.class, "tileentity_wand_jigsaw"); - put(TileEntityWandSpawner.class, "tileentity_wand_spawner"); + put(TileEntityWandLogic.class, "tileentity_wand_spawner"); putNetwork(); putBombs(); diff --git a/src/main/java/com/hbm/world/gen/util/DungeonSpawnerActions.java b/src/main/java/com/hbm/world/gen/util/LogicBlockActions.java similarity index 91% rename from src/main/java/com/hbm/world/gen/util/DungeonSpawnerActions.java rename to src/main/java/com/hbm/world/gen/util/LogicBlockActions.java index 252bc543b..2b3682c7c 100644 --- a/src/main/java/com/hbm/world/gen/util/DungeonSpawnerActions.java +++ b/src/main/java/com/hbm/world/gen/util/LogicBlockActions.java @@ -4,6 +4,7 @@ import com.hbm.blocks.BlockDummyable; import com.hbm.blocks.ModBlocks; import com.hbm.blocks.generic.BlockSkeletonHolder; import com.hbm.blocks.generic.DungeonSpawner; +import com.hbm.blocks.generic.LogicBlock; import com.hbm.entity.item.EntityFallingBlockNT; import com.hbm.entity.missile.EntityMissileTier2; import com.hbm.entity.mob.EntityUndeadSoldier; @@ -30,11 +31,11 @@ import net.minecraftforge.common.util.ForgeDirection; import java.util.*; import java.util.function.Consumer; -public class DungeonSpawnerActions { +public class LogicBlockActions { - public static LinkedHashMap> actions = new LinkedHashMap<>(); + public static LinkedHashMap> actions = new LinkedHashMap<>(); - public static Consumer PHASE_ABERRATOR = (tile) -> { + public static Consumer PHASE_ABERRATOR = (tile) -> { World world = tile.getWorldObj(); int x = tile.xCoord; int y = tile.yCoord; @@ -79,7 +80,7 @@ public class DungeonSpawnerActions { } }; - public static Consumer COLLAPSE_ROOF_RAD_5 = (tile) -> { + public static Consumer COLLAPSE_ROOF_RAD_5 = (tile) -> { World world = tile.getWorldObj(); int x = tile.xCoord; int y = tile.yCoord; @@ -115,7 +116,7 @@ public class DungeonSpawnerActions { }; - public static Consumer FODDER_WAVE = (tile) -> { + public static Consumer FODDER_WAVE = (tile) -> { World world = tile.getWorldObj(); int x = tile.xCoord; int y = tile.yCoord; @@ -134,7 +135,7 @@ public class DungeonSpawnerActions { } }; - public static Consumer PUZZLE_TEST = (tile) -> { + public static Consumer PUZZLE_TEST = (tile) -> { World world = tile.getWorldObj(); int x = tile.xCoord; int y = tile.yCoord; @@ -151,7 +152,7 @@ public class DungeonSpawnerActions { } }; - public static Consumer MISSILE_STRIKE = (tile) -> { + public static Consumer MISSILE_STRIKE = (tile) -> { World world = tile.getWorldObj(); int x = tile.xCoord; int y = tile.yCoord; @@ -176,7 +177,7 @@ public class DungeonSpawnerActions { world.setBlock(x,y,z, ModBlocks.block_electrical_scrap); }; - public static Consumer RAD_CONTAINMENT_SYSTEM = (tile) -> { + public static Consumer RAD_CONTAINMENT_SYSTEM = (tile) -> { World world = tile.getWorldObj(); int x = tile.xCoord; int y = tile.yCoord; @@ -254,9 +255,10 @@ public class DungeonSpawnerActions { //register new actions here static{ - actions.put("PHASE_ABERRATOR", PHASE_ABERRATOR); - actions.put("COLLAPSE_ROOF_RAD_5", COLLAPSE_ROOF_RAD_5); + //example actions actions.put("FODDER_WAVE", FODDER_WAVE); + actions.put("ABERRATOR", PHASE_ABERRATOR); + actions.put("COLLAPSE_ROOF_RAD_5", COLLAPSE_ROOF_RAD_5); actions.put("PUZZLE_TEST", PUZZLE_TEST); actions.put("MISSILE_STRIKE", MISSILE_STRIKE); actions.put("IRRADIATE_ENTITIES_AOE", RAD_CONTAINMENT_SYSTEM); diff --git a/src/main/java/com/hbm/world/gen/util/DungeonSpawnerConditions.java b/src/main/java/com/hbm/world/gen/util/LogicBlockConditions.java similarity index 79% rename from src/main/java/com/hbm/world/gen/util/DungeonSpawnerConditions.java rename to src/main/java/com/hbm/world/gen/util/LogicBlockConditions.java index 1e0cc9d5a..5065a38fd 100644 --- a/src/main/java/com/hbm/world/gen/util/DungeonSpawnerConditions.java +++ b/src/main/java/com/hbm/world/gen/util/LogicBlockConditions.java @@ -3,9 +3,9 @@ package com.hbm.world.gen.util; import com.hbm.blocks.ModBlocks; import com.hbm.blocks.generic.BlockPedestal; import com.hbm.blocks.generic.DungeonSpawner; +import com.hbm.blocks.generic.LogicBlock; import com.hbm.entity.mob.EntityUndeadSoldier; import com.hbm.items.ModItems; -import com.hbm.tileentity.machine.storage.TileEntityCrateBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; @@ -14,19 +14,18 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; import java.util.ArrayList; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.function.Function; -public class DungeonSpawnerConditions { +public class LogicBlockConditions { - public static LinkedHashMap> conditions = new LinkedHashMap<>(); + public static LinkedHashMap> conditions = new LinkedHashMap<>(); /**For use with interactions, for having them handle all conditional tasks*/ - public static Function EMPTY = (tile) -> false; + public static Function EMPTY = (tile) -> false; - public static Function ABERRATOR = (tile) -> { + public static Function ABERRATOR = (tile) -> { World world = tile.getWorldObj(); if(world.difficultySetting.ordinal() == 0) return false; int x = tile.xCoord; @@ -45,7 +44,7 @@ public class DungeonSpawnerConditions { return false; }; - public static Function PLAYER_CUBE_5 = (tile) -> { + public static Function PLAYER_CUBE_5 = (tile) -> { World world = tile.getWorldObj(); int x = tile.xCoord; int y = tile.yCoord; @@ -53,7 +52,7 @@ public class DungeonSpawnerConditions { return !world.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y - 2, z + 1).expand(5, 5, 5)).isEmpty(); }; - public static Function REDSTONE = (tile) -> { + public static Function REDSTONE = (tile) -> { World world = tile.getWorldObj(); int x = tile.xCoord; int y = tile.yCoord; @@ -62,7 +61,7 @@ public class DungeonSpawnerConditions { return world.isBlockIndirectlyGettingPowered(x,y,z); }; - public static Function PUZZLE_TEST = (tile) -> { + public static Function PUZZLE_TEST = (tile) -> { World world = tile.getWorldObj(); int x = tile.xCoord; int y = tile.yCoord; @@ -88,6 +87,7 @@ public class DungeonSpawnerConditions { //register new conditions here static { + //example conditions conditions.put("EMPTY", EMPTY); conditions.put("ABERRATOR", ABERRATOR); conditions.put("PLAYER_CUBE_5", PLAYER_CUBE_5); diff --git a/src/main/java/com/hbm/world/gen/util/DungeonSpawnerInteractions.java b/src/main/java/com/hbm/world/gen/util/LogicBlockInteractions.java similarity index 73% rename from src/main/java/com/hbm/world/gen/util/DungeonSpawnerInteractions.java rename to src/main/java/com/hbm/world/gen/util/LogicBlockInteractions.java index 32c19b81d..decf997a6 100644 --- a/src/main/java/com/hbm/world/gen/util/DungeonSpawnerInteractions.java +++ b/src/main/java/com/hbm/world/gen/util/LogicBlockInteractions.java @@ -1,30 +1,22 @@ package com.hbm.world.gen.util; -import com.hbm.blocks.generic.DungeonSpawner.TileEntityDungeonSpawner; -import com.hbm.entity.missile.EntityMissileTier2; +import com.hbm.blocks.generic.LogicBlock; +import com.hbm.blocks.generic.LogicBlock.TileEntityLogicBlock; import com.hbm.items.ModItems; import com.hbm.potion.HbmPotion; -import com.hbm.tileentity.TileEntityDoorGeneric; -import com.hbm.util.Vec3NT; -import com.hbm.world.WorldUtil; -import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.potion.PotionEffect; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; import java.util.ArrayList; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.function.Consumer; /**Interactions are called when the player right-clicks the block**/ -public class DungeonSpawnerInteractions { +public class LogicBlockInteractions { /**Consumer consists of world instance, tile entity instance, three ints for coordinates, one int for block side, and player instance, * in that order **/ @@ -32,23 +24,23 @@ public class DungeonSpawnerInteractions { public static Consumer TEST = (array) -> { World world = (World) array[0]; - TileEntityDungeonSpawner spawner = (TileEntityDungeonSpawner) array[1]; + LogicBlock.TileEntityLogicBlock logic = (LogicBlock.TileEntityLogicBlock) array[1]; int x = (int) array[2]; int y = (int) array[3]; int z = (int) array[4]; EntityPlayer player = (EntityPlayer) array[5]; int side = (int) array[6]; - if(spawner.phase > 1) return; + if(logic.phase > 1) return; if(player.getHeldItem() != null) player.getHeldItem().stackSize--; - spawner.phase++; + logic.phase++; }; public static Consumer RAD_CONTAINMENT_SYSTEM = (array) -> { - TileEntityDungeonSpawner spawner = (TileEntityDungeonSpawner) array[1]; + LogicBlock.TileEntityLogicBlock logic = (LogicBlock.TileEntityLogicBlock) array[1]; EntityPlayer player = (EntityPlayer) array[5]; if(player.getHeldItem() != null && player.getHeldItem().getItem() == ModItems.key){ @@ -58,8 +50,8 @@ public class DungeonSpawnerInteractions { EnumChatFormatting.RESET + " Radiation treatment administered")); player.addPotionEffect(new PotionEffect(HbmPotion.radaway.getId(), 3 * 60 * 20, 4)); player.addPotionEffect(new PotionEffect(HbmPotion.radx.getId(), 3 * 60 * 20, 4)); - spawner.phase = 2; - spawner.timer = 0; + logic.phase = 2; + logic.timer = 0; } }; diff --git a/src/main/resources/assets/hbm/lang/en_US.lang b/src/main/resources/assets/hbm/lang/en_US.lang index dcb6d68b3..c5fd461eb 100644 --- a/src/main/resources/assets/hbm/lang/en_US.lang +++ b/src/main/resources/assets/hbm/lang/en_US.lang @@ -5279,7 +5279,7 @@ tile.ducrete_smooth_stairs.name=Ducrete Stairs tile.dummy_block.name=Dummy Block tile.dummy_port.name=Dummy Block (Electricity Port) tile.dungeon_chain.name=Metal Chain -tile.dungeon_spawner.name=Dungeon Action Block +tile.logic_block.name=Dungeon Action Block tile.dynamite.name=Dynamite tile.emp_bomb.name=EMP Device tile.factory_advanced_conductor.name=Advanced Factory Electricity Port @@ -6062,7 +6062,7 @@ tile.volcano_rad_core.name=Rad Volcano Core tile.wand_air.name=Structure Wand Block (Air) tile.wand_loot.name=Structure Wand Block (Lootable) tile.wand_jigsaw.name=Structure Wand Block (Jigsaw) -tile.wand_spawner.name=Structure Wand Block (Actions) +tile.wand_logic.name=Structure Wand Block (Logic) tile.waste_earth.name=Dead Grass tile.waste_leaves.name=Dead Leaves tile.waste_log.name=Charred Log diff --git a/src/main/resources/assets/hbm/textures/blocks/logic_block.png b/src/main/resources/assets/hbm/textures/blocks/logic_block.png new file mode 100644 index 000000000..9e0d69e2f Binary files /dev/null and b/src/main/resources/assets/hbm/textures/blocks/logic_block.png differ diff --git a/src/main/resources/assets/hbm/textures/blocks/wand_spawner.png b/src/main/resources/assets/hbm/textures/blocks/wand_logic.png similarity index 100% rename from src/main/resources/assets/hbm/textures/blocks/wand_spawner.png rename to src/main/resources/assets/hbm/textures/blocks/wand_logic.png diff --git a/src/main/resources/assets/hbm/textures/blocks/wand_spawner_top.png b/src/main/resources/assets/hbm/textures/blocks/wand_logic_top.png similarity index 100% rename from src/main/resources/assets/hbm/textures/blocks/wand_spawner_top.png rename to src/main/resources/assets/hbm/textures/blocks/wand_logic_top.png