diff --git a/src/main/java/com/hbm/blocks/ModBlocks.java b/src/main/java/com/hbm/blocks/ModBlocks.java index f6dcd2065..5f3de7f83 100644 --- a/src/main/java/com/hbm/blocks/ModBlocks.java +++ b/src/main/java/com/hbm/blocks/ModBlocks.java @@ -1243,6 +1243,9 @@ public class ModBlocks { public static Block wand_air; public static Block wand_loot; public static Block wand_jigsaw; + public static Block wand_logic; + + public static Block logic_block; public static Material materialGas = new MaterialGas(); @@ -1977,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"); @@ -2396,6 +2399,10 @@ 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_logic = new BlockWandLogic().setBlockName("wand_logic").setBlockTextureName(RefStrings.MODID + ":wand_logic"); + + logic_block = new LogicBlock().setBlockName("logic_block").setBlockTextureName(RefStrings.MODID + ":logic_block"); + } private static void registerBlock() { @@ -3542,6 +3549,9 @@ public class ModBlocks { register(wand_air); register(wand_loot); register(wand_jigsaw); + register(wand_logic); + + register(logic_block); } private static void register(Block b) { diff --git a/src/main/java/com/hbm/blocks/generic/BlockWandLogic.java b/src/main/java/com/hbm/blocks/generic/BlockWandLogic.java new file mode 100644 index 000000000..01d8df298 --- /dev/null +++ b/src/main/java/com/hbm/blocks/generic/BlockWandLogic.java @@ -0,0 +1,343 @@ +package com.hbm.blocks.generic; + +import api.hbm.block.IToolable; +import com.hbm.blocks.IBlockSideRotation; +import com.hbm.blocks.ILookOverlay; +import com.hbm.blocks.ITooltipProvider; +import com.hbm.blocks.ModBlocks; +import com.hbm.config.StructureConfig; +import com.hbm.interfaces.IBomb; +import com.hbm.interfaces.ICopiable; +import com.hbm.lib.RefStrings; +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.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 io.netty.buffer.ByteBuf; +import net.minecraft.block.Block; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IIcon; +import net.minecraft.util.MathHelper; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.common.util.ForgeDirection; + +import java.util.ArrayList; +import java.util.List; + +public class BlockWandLogic extends BlockContainer implements ILookOverlay, IToolable, ITooltipProvider, IBlockSideRotation, IBomb { + + @SideOnly(Side.CLIENT) protected IIcon iconTop; + + public BlockWandLogic() { + super(Material.iron); + } + + @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister iconRegister) { + this.blockIcon = iconRegister.registerIcon(RefStrings.MODID + ":wand_logic"); + this.iconTop = iconRegister.registerIcon(RefStrings.MODID + ":wand_logic_top"); + } + + @Override + public IIcon getIcon(int side, int meta) { + return (side <= 1) ? iconTop : blockIcon; + } + + @Override + public int getRotationFromSide(IBlockAccess world, int x, int y, int z, int side) { + if(side == 0) return IBlockSideRotation.topToBottom(world.getBlockMetadata(x, y, z)); + if(side == 1) return world.getBlockMetadata(x, y, z); + return 0; + } + + @Override + public int getRenderType() { + return IBlockSideRotation.getRenderType(); + } + + @Override + public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemStack) { + int i = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3; + + if (i == 0) world.setBlockMetadataWithNotify(x, y, z, 3, 2); + if (i == 1) world.setBlockMetadataWithNotify(x, y, z, 2, 2); + if (i == 2) world.setBlockMetadataWithNotify(x, y, z, 0, 2); + if (i == 3) world.setBlockMetadataWithNotify(x, y, z, 1, 2); + + ForgeDirection dir = ForgeDirection.UNKNOWN; + switch(i){ + case 0: dir = ForgeDirection.SOUTH;break; + case 1: dir = ForgeDirection.WEST; break; + case 2: dir = ForgeDirection.NORTH;break; + case 3: dir = ForgeDirection.EAST; break; + } + TileEntity te = world.getTileEntity(x, y, z); + if(te instanceof TileEntityWandLogic) + ((TileEntityWandLogic)te).placedRotation = dir.ordinal(); + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float fX, float fY, float fZ) { + + ItemStack stack = player.getHeldItem(); + + if (stack != null && stack.getItem() instanceof ItemBlock && !player.isSneaking()) { + ItemBlock ib = (ItemBlock) stack.getItem(); + Block block = ib.field_150939_a; + + if (block.renderAsNormalBlock() && block != this) { + + TileEntity tile = world.getTileEntity(x, y, z); + + if(tile instanceof TileEntityWandLogic){ + TileEntityWandLogic logic = (TileEntityWandLogic) tile; + logic.disguise = block; + logic.disguiseMeta = stack.getItemDamage() & 15; + return true; + } + } + } + return super.onBlockActivated(world, x, y, z, player, side, fX, fY, fZ); + } + + @Override + 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 TileEntityWandLogic)) return false; + + TileEntityWandLogic logic = (TileEntityWandLogic) te; + + switch(tool) { + case SCREWDRIVER: + List actionNames = LogicBlockActions.getActionNames(); + int indexA = actionNames.indexOf(logic.actionID); + + indexA += player.isSneaking() ? -1 : 1; + indexA = MathHelper.clamp_int(indexA, 0, actionNames.size() - 1); + + logic.actionID = actionNames.get(indexA); + return true; + case DEFUSER: + List conditionNames = LogicBlockConditions.getConditionNames(); + int indexC = conditionNames.indexOf(logic.conditionID); + + indexC += player.isSneaking() ? -1 : 1; + indexC = MathHelper.clamp_int(indexC, 0, conditionNames.size() - 1); + + logic.conditionID = conditionNames.get(indexC); + + return true; + case HAND_DRILL: + List interactionNames = LogicBlockInteractions.getInteractionNames(); + int indexI = interactionNames.indexOf(logic.interactionID); + + indexI += player.isSneaking() ? -1 : 1; + indexI = MathHelper.clamp_int(indexI, 0, interactionNames.size() - 1); + + logic.interactionID = interactionNames.get(indexI); + + return true; + + default: return false; + } + } + + @Override + public void printHook(RenderGameOverlayEvent.Pre event, World world, int x, int y, int z) { + TileEntity te = world.getTileEntity(x, y, z); + + if(!(te instanceof TileEntityWandLogic)) return; + + TileEntityWandLogic logic = (TileEntityWandLogic) te; + + List text = new ArrayList<>(); + text.add("Action: " + logic.actionID); + text.add("Condition: " + logic.conditionID); + text.add("Interaction: " + (logic.interactionID != null ? logic.interactionID : "None")); + + String block; + + if(logic.disguise != null && logic.disguise != Blocks.air) + block = I18nUtil.resolveKey(logic.disguise.getUnlocalizedName() + ".name"); + else + block = "None"; + + text.add("Disguise Block: " + block); + + ILookOverlay.printGeneric(event, I18nUtil.resolveKey(getUnlocalizedName() + ".name"), 0xffff00, 0x404000, text); + } + + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) { + list.add(EnumChatFormatting.GOLD + "Use screwdriver to cycle forwards through the action list, shift click to go back"); + list.add(EnumChatFormatting.GOLD + "Use defuser to cycle forwards through the condition list, shift click to go back"); + list.add(EnumChatFormatting.GOLD + "Use hand drill to cycle forwards through the interaction list, shift click to go back"); + list.add(EnumChatFormatting.YELLOW + "Use a detonator to transform"); + } + + @Override + public TileEntity createNewTileEntity(World worldIn, int meta) { + 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 TileEntityWandLogic)) return null; + + ((TileEntityWandLogic) te).triggerReplace = true; + + return BombReturnCode.TRIGGERED; + } + + public static class TileEntityWandLogic extends TileEntityLoadedBase implements INBTTileEntityTransformable, ICopiable { + private boolean triggerReplace; + + public int placedRotation; + + Block disguise; + int disguiseMeta = -1; + + public String actionID = "FODDER_WAVE"; + public String conditionID = "PLAYER_CUBE_5"; + public String interactionID; + + @Override + public void updateEntity() { + if(!worldObj.isRemote) { + if(triggerReplace) { + // On the first tick of this TE, replace with intended block and fill with loot + replace(); + } else { + networkPackNT(15); + } + } + } + + private void replace() { + 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.logic_block); + + TileEntity te = worldObj.getTileEntity(xCoord, yCoord, zCoord); + + if(te == null || te instanceof BlockWandLoot.TileEntityWandLoot) { + 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 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; + } + + } + + @Override + public void transformTE(World world, int coordBaseMode) { + triggerReplace = !StructureConfig.debugStructures; + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + nbt.setString("actionID", actionID); + nbt.setString("conditionID", conditionID); + nbt.setString("interactionID", interactionID); + nbt.setInteger("rotation", placedRotation); + if(disguise != null){ + nbt.setString("disguise", GameRegistry.findUniqueIdentifierFor(disguise).toString()); + nbt.setInteger("disguiseMeta", disguiseMeta); + } + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + actionID = nbt.getString("actionID"); + conditionID = nbt.getString("conditionID"); + interactionID = nbt.getString("interactionID"); + placedRotation = nbt.getInteger("rotation"); + if(nbt.hasKey("disguise")){ + disguise = Block.getBlockFromName(nbt.getString("disguise")); + disguiseMeta = nbt.getInteger("disguiseMeta"); + } + } + + @Override + public void serialize(ByteBuf buf) { + buf.writeInt(placedRotation); + BufferUtil.writeString(buf, actionID); + BufferUtil.writeString(buf, conditionID); + BufferUtil.writeString(buf, interactionID); + buf.writeInt(Block.getIdFromBlock(disguise)); + buf.writeInt(disguiseMeta); + } + + @Override + public void deserialize(ByteBuf buf) { + placedRotation = buf.readInt(); + actionID = BufferUtil.readString(buf); + conditionID = BufferUtil.readString(buf); + interactionID = BufferUtil.readString(buf); + disguise = Block.getBlockById(buf.readInt()); + disguiseMeta = buf.readInt(); + } + + @Override + public NBTTagCompound getSettings(World world, int x, int y, int z) { + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setString("actionID", actionID); + nbt.setString("conditionID", conditionID); + if(interactionID != null) + nbt.setString("interactionID", interactionID); + if(disguise != null){ + nbt.setString("disguise", GameRegistry.findUniqueIdentifierFor(disguise).toString()); + nbt.setInteger("disguiseMeta", disguiseMeta); + } + + return nbt; + } + + @Override + public void pasteSettings(NBTTagCompound nbt, int index, World world, EntityPlayer player, int x, int y, int z) { + actionID = nbt.getString("actionID"); + conditionID = nbt.getString("conditionID"); + interactionID = nbt.getString("interactionID"); + if(nbt.hasKey("disguise")){ + disguise = Block.getBlockFromName(nbt.getString("disguise")); + disguiseMeta = nbt.getInteger("disguiseMeta"); + } + } + } +} 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/entity/mob/EntityUndeadSoldier.java b/src/main/java/com/hbm/entity/mob/EntityUndeadSoldier.java index 1a18c36c7..f2b042085 100644 --- a/src/main/java/com/hbm/entity/mob/EntityUndeadSoldier.java +++ b/src/main/java/com/hbm/entity/mob/EntityUndeadSoldier.java @@ -16,10 +16,11 @@ import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.passive.EntityVillager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.world.EnumDifficulty; import net.minecraft.world.World; public class EntityUndeadSoldier extends EntityMob { - + public static final int DW_TYPE = 12; public static final byte TYPE_ZOMBIE = 0; public static final byte TYPE_SKELETON = 1; @@ -66,7 +67,7 @@ public class EntityUndeadSoldier extends EntityMob { this.setCurrentItemOrArmor(3, new ItemStack(ModItems.taurun_plate)); this.setCurrentItemOrArmor(2, new ItemStack(ModItems.taurun_legs)); this.setCurrentItemOrArmor(1, new ItemStack(ModItems.taurun_boots)); - + int gun = rand.nextInt(5); if(gun == 0) this.setCurrentItemOrArmor(0, new ItemStack(ModItems.gun_heavy_revolver)); if(gun == 1) this.setCurrentItemOrArmor(0, new ItemStack(ModItems.gun_light_revolver)); @@ -74,7 +75,7 @@ public class EntityUndeadSoldier extends EntityMob { if(gun == 3) this.setCurrentItemOrArmor(0, new ItemStack(ModItems.gun_maresleg)); if(gun == 4) this.setCurrentItemOrArmor(0, new ItemStack(ModItems.gun_greasegun)); } - + @Override protected String getLivingSound() { byte type = this.dataWatcher.getWatchableObjectByte(DW_TYPE); @@ -110,7 +111,12 @@ public class EntityUndeadSoldier extends EntityMob { public EnumCreatureAttribute getCreatureAttribute() { return EnumCreatureAttribute.UNDEAD; } - + + @Override + public boolean getCanSpawnHere() { + return this.worldObj.difficultySetting != EnumDifficulty.PEACEFUL && this.worldObj.checkNoEntityCollision(this.boundingBox) && this.worldObj.getCollidingBoundingBoxes(this, this.boundingBox).isEmpty() && !this.worldObj.isAnyLiquid(this.boundingBox); + } + @Override protected void dropFewItems(boolean player, int loot) { } @Override protected void dropEquipment(boolean player, int loot) { } } diff --git a/src/main/java/com/hbm/main/MainRegistry.java b/src/main/java/com/hbm/main/MainRegistry.java index 4c8e7f954..0891e4012 100644 --- a/src/main/java/com/hbm/main/MainRegistry.java +++ b/src/main/java/com/hbm/main/MainRegistry.java @@ -877,6 +877,8 @@ public class MainRegistry { BlockToolConversion.registerRecipes(); AchievementHandler.register(); + MobUtil.intializeMobPools(); + proxy.registerMissileItems(); // Load compatibility for OC. diff --git a/src/main/java/com/hbm/main/ModEventHandler.java b/src/main/java/com/hbm/main/ModEventHandler.java index cd368b165..655656174 100644 --- a/src/main/java/com/hbm/main/ModEventHandler.java +++ b/src/main/java/com/hbm/main/ModEventHandler.java @@ -387,74 +387,18 @@ public class ModEventHandler { if(entity instanceof EntityZombie) { if(world.rand.nextFloat() < 0.005F && soot > 2) { // full hazmat zombine - equipFullSet(entity, ModItems.hazmat_helmet, ModItems.hazmat_plate, ModItems.hazmat_legs, ModItems.hazmat_boots); + MobUtil.equipFullSet(entity, ModItems.hazmat_helmet, ModItems.hazmat_plate, ModItems.hazmat_legs, ModItems.hazmat_boots); return; } - - if(world.rand.nextFloat() < 0.005F && soot > 20) { // full security zombine - equipFullSet(entity, ModItems.security_helmet, ModItems.security_plate, ModItems.security_legs, ModItems.security_boots); - return; - } - - slotPools.put(4, createSlotPool(8000, new Object[][]{ //new slots, smooth, brushed, no wrinkles // old slots, wrinkled, rusty, not smooth - {ModItems.gas_mask_m65, 16}, {ModItems.gas_mask_olde, 12}, {ModItems.mask_of_infamy, 8}, - {ModItems.gas_mask_mono, 8}, {ModItems.robes_helmet, 32}, {ModItems.no9, 16}, - {ModItems.cobalt_helmet, 2}, {ModItems.rag_piss, 1}, {ModItems.hat, 1}, {ModItems.alloy_helmet, 2}, - {ModItems.titanium_helmet, 4}, {ModItems.steel_helmet, 8} - })); - slotPools.put(3, createSlotPool(7000, new Object[][]{ - {ModItems.starmetal_plate, 1}, {ModItems.cobalt_plate, 2}, {ModItems.robes_plate, 32}, - {ModItems.jackt, 32}, {ModItems.jackt2, 32}, {ModItems.alloy_plate, 2}, - {ModItems.steel_plate, 2} - })); - slotPools.put(2, createSlotPool(7000, new Object[][]{ - {ModItems.zirconium_legs, 1}, {ModItems.cobalt_legs, 2}, {ModItems.steel_legs, 16}, - {ModItems.titanium_legs, 8}, {ModItems.robes_legs, 32}, {ModItems.alloy_legs, 2} - })); - slotPools.put(1, createSlotPool(7000, new Object[][]{ - {ModItems.robes_boots, 32}, {ModItems.steel_boots, 16}, {ModItems.cobalt_boots, 2}, {ModItems.alloy_boots, 2} - })); - slotPools.put(0, createSlotPool(10000, new Object[][]{ - {ModItems.pipe_lead, 30}, {ModItems.crowbar, 25}, {ModItems.geiger_counter, 20}, - {ModItems.reer_graar, 16}, {ModItems.steel_pickaxe, 12}, {ModItems.stopsign, 10}, - {ModItems.sopsign, 8}, {ModItems.chernobylsign, 6}, {ModItems.steel_sword, 15}, - {ModItems.alloy_axe, 5}, {ModItems.titanium_sword, 8}, {ModItems.lead_gavel, 4}, - {ModItems.wrench, 20}, {ModItems.cobalt_decorated_sword, 2}, {ModItems.detonator_de, 1} - })); + slotPools = MobUtil.slotPoolCommon; } else if(entity instanceof EntitySkeleton) { - - slotPools.put(4, createSlotPool(12000, new Object[][]{ - {ModItems.gas_mask_m65, 16}, {ModItems.gas_mask_olde, 12}, {ModItems.mask_of_infamy, 8}, - {ModItems.gas_mask_mono, 8}, {ModItems.robes_helmet, 32}, {ModItems.no9, 16}, - {ModItems.cobalt_helmet, 2}, {ModItems.rag_piss, 1}, {ModItems.hat, 1}, {ModItems.alloy_helmet, 2}, - {ModItems.titanium_helmet, 4}, {ModItems.steel_helmet, 8} - })); - slotPools.put(3, createSlotPool(10000, new Object[][]{ - {ModItems.starmetal_plate, 1}, {ModItems.cobalt_plate, 2}, {ModItems.alloy_plate, 2}, //sadly they cant wear jackets bc it breaks it - {ModItems.steel_plate, 8}, {ModItems.titanium_plate, 4} - })); - slotPools.put(2, createSlotPool(10000, new Object[][]{ - {ModItems.zirconium_legs, 1}, {ModItems.cobalt_legs, 2}, {ModItems.steel_legs, 16}, - {ModItems.titanium_legs, 8}, {ModItems.robes_legs, 32}, {ModItems.alloy_legs, 2}, - })); - slotPools.put(1, createSlotPool(10000, new Object[][]{ - {ModItems.robes_boots, 32}, {ModItems.steel_boots, 16}, {ModItems.cobalt_boots, 2}, {ModItems.alloy_boots, 2}, - {ModItems.titanium_boots, 6} - })); - + slotPools = MobUtil.slotPoolRanged; ItemStack bowReplacement = getSkelegun(soot, world.rand); slotPools.put(0, createSlotPool(50, bowReplacement != null ? new Object[][]{{bowReplacement, 1}} : new Object[][]{})); } - assignItemsToEntity(entity, slotPools); - } - - private void equipFullSet(EntityLivingBase entity, Item helmet, Item chest, Item legs, Item boots) { //for brainlets (me) to add more armorsets later when i forget about how this works - entity.setCurrentItemOrArmor(4, new ItemStack(helmet)); //p_70062_1_ is the slot number - entity.setCurrentItemOrArmor(3, new ItemStack(chest)); - entity.setCurrentItemOrArmor(2, new ItemStack(legs)); - entity.setCurrentItemOrArmor(1, new ItemStack(boots)); + MobUtil.assignItemsToEntity(entity, slotPools, rand); } private List createSlotPool(int nullWeight, Object[][] items) { @@ -473,74 +417,30 @@ public class ModEventHandler { return pool; } - - public void assignItemsToEntity(EntityLivingBase entity, Map> slotPools) { - for (Map.Entry> entry : slotPools.entrySet()) { - int slot = entry.getKey(); - List pool = entry.getValue(); - - WeightedRandomObject choice = (WeightedRandomObject) WeightedRandom.getRandomItem(rand, pool); //NullPointerException sludge fix - if (choice == null) { - continue; - } - - ItemStack stack = choice.asStack(); - if (stack == null || stack.getItem() == null) { - continue; - } - - if (stack.getItem() == ModItems.gas_mask_m65 //eyesore - || stack.getItem() == ModItems.gas_mask_olde - || stack.getItem() == ModItems.gas_mask_mono) { - ArmorUtil.installGasMaskFilter(stack, new ItemStack(ModItems.gas_mask_filter)); - } - - entity.setCurrentItemOrArmor(slot, stack); - - //Give skeleton AI if it has a gun - if (slot == 0 && entity instanceof EntitySkeleton && pool == slotPools.get(0)) { - addFireTask((EntityLiving) entity); - } - } - } - private static ItemStack getSkelegun(float soot, Random rand) { - if(!MobConfig.enableMobWeapons) return null; - if(rand.nextDouble() > Math.log(soot) * 0.25) return null; + if (!MobConfig.enableMobWeapons) return null; + if (rand.nextDouble() > Math.log(soot) * 0.25) return null; - ArrayList pool = new ArrayList(); - pool.add(new WeightedRandomObject(new ItemStack(ModItems.gun_light_revolver), 12)); - pool.add(new WeightedRandomObject(new ItemStack(ModItems.gun_heavy_revolver), 8)); + ArrayList pool = new ArrayList<>(); - if(soot > 2) pool.add(new WeightedRandomObject(new ItemStack(ModItems.gun_pepperbox), 10)); - if(soot > 2) pool.add(new WeightedRandomObject(new ItemStack(ModItems.gun_henry), 8)); - if(soot > 2) pool.add(new WeightedRandomObject(new ItemStack(ModItems.gun_greasegun), 6)); - - if(soot > 4) pool.add(new WeightedRandomObject(new ItemStack(ModItems.gun_maresleg), 4)); - if(soot > 4) pool.add(new WeightedRandomObject(new ItemStack(ModItems.gun_uzi), 6)); - - if(soot > 8) pool.add(new WeightedRandomObject(new ItemStack(ModItems.gun_spas12), 3)); - if(soot > 8) pool.add(new WeightedRandomObject(new ItemStack(ModItems.gun_am180), 4)); - - if(soot > 12) pool.add(new WeightedRandomObject(new ItemStack(ModItems.gun_congolake), 1)); + if(soot < 0.3){ + pool.add(new WeightedRandomObject(new ItemStack(ModItems.gun_pepperbox), 5)); + pool.add(new WeightedRandomObject(null, 20)); + } else if(soot > 0.3 && soot < 1) { + pool.addAll(MobUtil.slotPoolGuns.get(0.3)); + } else if (soot < 3) { + pool.addAll(MobUtil.slotPoolGuns.get(1D)); + } else if (soot < 5) { + pool.addAll(MobUtil.slotPoolGuns.get(3D)); + } else { + pool.addAll(MobUtil.slotPoolGuns.get(5D)); + } WeightedRandomObject selected = (WeightedRandomObject) WeightedRandom.getRandomItem(rand, pool); return selected.asStack(); } - // these fucking tasks keep stacking on top of themselves - private static void addFireTask(EntityLiving entity) { - entity.setEquipmentDropChance(0, 0); // Prevent dropping guns - - for(Object entry : entity.tasks.taskEntries) { - EntityAITasks.EntityAITaskEntry task = (EntityAITasks.EntityAITaskEntry) entry; - if(task.action instanceof EntityAIFireGun) return; - } - - entity.tasks.addTask(3, new EntityAIFireGun(entity)); - } - @SubscribeEvent public void addAITasks(EntityJoinWorldEvent event) { if(event.world.isRemote || !(event.entity instanceof EntityLiving)) return; @@ -549,7 +449,7 @@ public class ModEventHandler { ItemStack held = living.getHeldItem(); if(held != null && held.getItem() instanceof ItemGunBaseNT) { - addFireTask(living); + MobUtil.addFireTask(living); } } 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 ca3281bd1..1c938ab18 100644 --- a/src/main/java/com/hbm/tileentity/TileMappings.java +++ b/src/main/java/com/hbm/tileentity/TileMappings.java @@ -19,7 +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.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; @@ -208,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"); @@ -236,6 +239,7 @@ public class TileMappings { put(TileEntityWandLoot.class, "tileentity_wand_loot"); put(TileEntityWandJigsaw.class, "tileentity_wand_jigsaw"); + put(TileEntityWandLogic.class, "tileentity_wand_spawner"); putNetwork(); putBombs(); @@ -428,7 +432,7 @@ public class TileMappings { put(TileEntityCranePartitioner.class, "tileentity_partitioner"); put(TileEntityFan.class, "tileentity_fan"); put(TileEntityPistonInserter.class, "tileentity_piston_inserter"); - + put(TileEntityPneumoTube.class, "tileentity_pneumatic_tube"); put(TileEntityRadioTorchSender.class, "tileentity_rtty_sender"); diff --git a/src/main/java/com/hbm/util/MobUtil.java b/src/main/java/com/hbm/util/MobUtil.java new file mode 100644 index 000000000..8779c1ed2 --- /dev/null +++ b/src/main/java/com/hbm/util/MobUtil.java @@ -0,0 +1,197 @@ +package com.hbm.util; + +import com.hbm.entity.mob.ai.EntityAIFireGun; +import com.hbm.items.ModItems; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.ai.EntityAITasks; +import net.minecraft.entity.monster.EntitySkeleton; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.WeightedRandom; + +import java.util.*; + +public class MobUtil { + + + public static Map> slotPoolCommon = new HashMap<>(); + public static Map> slotPoolRanged = new HashMap<>(); + + public static Map> slotPoolAdv = new HashMap<>(); + public static Map> slotPoolAdvRanged; + /**Unlike the above two, the Double is interpreted as minimum soot level, instead of armor slot **/ + public static HashMap> slotPoolGuns = new HashMap<>(); + + + public static void intializeMobPools(){ + slotPoolCommon.put(4, createSlotPool(8000, new Object[][]{ //new slots, smooth, brushed, no wrinkles // old slots, wrinkled, rusty, not smooth + {ModItems.gas_mask_m65, 16}, {ModItems.gas_mask_olde, 12}, {ModItems.mask_of_infamy, 8}, + {ModItems.gas_mask_mono, 8}, {ModItems.robes_helmet, 32}, {ModItems.no9, 16}, + {ModItems.cobalt_helmet, 2}, {ModItems.rag_piss, 1}, {ModItems.hat, 1}, {ModItems.alloy_helmet, 2}, + {ModItems.titanium_helmet, 4}, {ModItems.steel_helmet, 8} + })); + slotPoolCommon.put(3, createSlotPool(7000, new Object[][]{ + {ModItems.starmetal_plate, 1}, {ModItems.cobalt_plate, 2}, {ModItems.robes_plate, 32}, + {ModItems.jackt, 32}, {ModItems.jackt2, 32}, {ModItems.alloy_plate, 2}, + {ModItems.steel_plate, 2} + })); + slotPoolCommon.put(2, createSlotPool(7000, new Object[][]{ + {ModItems.zirconium_legs, 1}, {ModItems.cobalt_legs, 2}, {ModItems.steel_legs, 16}, + {ModItems.titanium_legs, 8}, {ModItems.robes_legs, 32}, {ModItems.alloy_legs, 2} + })); + slotPoolCommon.put(1, createSlotPool(7000, new Object[][]{ + {ModItems.robes_boots, 32}, {ModItems.steel_boots, 16}, {ModItems.cobalt_boots, 2}, {ModItems.alloy_boots, 2} + })); + slotPoolCommon.put(0, createSlotPool(10000, new Object[][]{ + {ModItems.pipe_lead, 30}, {ModItems.crowbar, 25}, {ModItems.geiger_counter, 20}, + {ModItems.reer_graar, 16}, {ModItems.steel_pickaxe, 12}, {ModItems.stopsign, 10}, + {ModItems.sopsign, 8}, {ModItems.chernobylsign, 6}, {ModItems.steel_sword, 15}, + {ModItems.titanium_sword, 8}, {ModItems.lead_gavel, 4}, {ModItems.wrench_flipped, 2}, + {ModItems.wrench, 20} + })); + + slotPoolRanged.put(4, createSlotPool(12000, new Object[][]{ + {ModItems.gas_mask_m65, 16}, {ModItems.gas_mask_olde, 12}, {ModItems.mask_of_infamy, 8}, + {ModItems.gas_mask_mono, 8}, {ModItems.robes_helmet, 32}, {ModItems.no9, 16}, + {ModItems.rag_piss, 1}, {ModItems.goggles, 1}, {ModItems.alloy_helmet, 2}, + {ModItems.titanium_helmet, 4}, {ModItems.steel_helmet, 8} + })); + slotPoolRanged.put(3, createSlotPool(10000, new Object[][]{ + {ModItems.starmetal_plate, 1}, {ModItems.cobalt_plate, 2}, {ModItems.alloy_plate, 2}, //sadly they cant wear jackets bc it breaks it + {ModItems.steel_plate, 8}, {ModItems.titanium_plate, 4} + })); + slotPoolRanged.put(2, createSlotPool(10000, new Object[][]{ + {ModItems.zirconium_legs, 1}, {ModItems.cobalt_legs, 2}, {ModItems.steel_legs, 16}, + {ModItems.titanium_legs, 8}, {ModItems.robes_legs, 32}, {ModItems.alloy_legs, 2}, + })); + slotPoolRanged.put(1, createSlotPool(10000, new Object[][]{ + {ModItems.robes_boots, 32}, {ModItems.steel_boots, 16}, {ModItems.cobalt_boots, 2}, {ModItems.alloy_boots, 2}, + {ModItems.titanium_boots, 6} + })); + + slotPoolGuns.put(0.3, createSlotPool(new Object[][]{ + {ModItems.gun_light_revolver, 16}, {ModItems.gun_greasegun, 8}, {ModItems.gun_maresleg, 2} + })); + slotPoolGuns.put(1D, createSlotPool(new Object[][]{ + {ModItems.gun_light_revolver, 6}, {ModItems.gun_greasegun, 8}, {ModItems.gun_maresleg, 4}, {ModItems.gun_henry, 6} + })); + slotPoolGuns.put(3D, createSlotPool(new Object[][]{ + {ModItems.gun_uzi, 10}, {ModItems.gun_maresleg, 8}, {ModItems.gun_henry, 12}, {ModItems.gun_heavy_revolver, 4}, {ModItems.gun_flaregun, 2} + })); + slotPoolGuns.put(5D, createSlotPool(new Object[][]{ + {ModItems.gun_am180, 6}, {ModItems.gun_uzi, 10}, {ModItems.gun_spas12, 8}, {ModItems.gun_henry_lincoln, 2}, {ModItems.gun_heavy_revolver, 12}, {ModItems.gun_flaregun, 4}, {ModItems.gun_flamer, 2} + })); + + slotPoolAdv.put(4, createSlotPool(new Object[][]{ + {ModItems.security_helmet, 10}, {ModItems.t45_helmet, 4}, {ModItems.asbestos_helmet, 12}, + {ModItems.liquidator_helmet, 4}, {ModItems.no9, 12}, + {ModItems.hazmat_helmet, 6} + })); + slotPoolAdv.put(3, createSlotPool(new Object[][]{ + {ModItems.liquidator_plate, 4}, {ModItems.security_plate, 8}, {ModItems.asbestos_plate, 12}, + {ModItems.t45_plate, 4}, {ModItems.hazmat_plate, 6}, + {ModItems.steel_plate, 8} + })); + slotPoolAdv.put(2, createSlotPool(new Object[][]{ + {ModItems.liquidator_legs, 4}, {ModItems.security_legs, 8}, {ModItems.asbestos_legs, 12}, + {ModItems.t45_legs, 4}, {ModItems.hazmat_legs, 6}, + {ModItems.steel_legs, 8} + })); + slotPoolAdv.put(1, createSlotPool(new Object[][]{ + {ModItems.liquidator_boots, 4}, {ModItems.security_boots, 8}, {ModItems.asbestos_boots, 12}, + {ModItems.t45_boots, 4}, {ModItems.hazmat_boots, 6}, + {ModItems.robes_boots, 8} + })); + slotPoolAdv.put(0, createSlotPool(new Object[][]{ + {ModItems.pipe_lead, 20}, {ModItems.crowbar, 30}, {ModItems.geiger_counter, 20}, + {ModItems.reer_graar, 20}, {ModItems.wrench_flipped, 12}, {ModItems.stopsign, 16}, + {ModItems.sopsign, 4}, {ModItems.chernobylsign, 16}, + {ModItems.titanium_sword, 18}, {ModItems.lead_gavel, 8}, + {ModItems.wrench, 20} + })); + + slotPoolAdvRanged = new HashMap<>(slotPoolAdv); + slotPoolAdvRanged.remove(0); + + } + + public static List createSlotPool(int nullWeight, Object[][] items) { + List pool = new ArrayList<>(); + pool.add(new WeightedRandomObject(null, nullWeight)); + for (Object[] item : items) { + Object obj = item[0]; + int weight = (int) item[1]; + + if (obj instanceof Item) { + pool.add(new WeightedRandomObject(new ItemStack((Item) obj), weight)); + } else if (obj instanceof ItemStack) { //lol just make it pass ItemStack aswell + pool.add(new WeightedRandomObject(obj, weight)); + } + } + return pool; + } + public static List createSlotPool(Object[][] items) { + List pool = new ArrayList<>(); + for (Object[] item : items) { + Object obj = item[0]; + int weight = (int) item[1]; + + if (obj instanceof Item) { + pool.add(new WeightedRandomObject(new ItemStack((Item) obj), weight)); + } else if (obj instanceof ItemStack) { //lol just make it pass ItemStack aswell + pool.add(new WeightedRandomObject(obj, weight)); + } + } + return pool; + } + + public static void equipFullSet(EntityLivingBase entity, Item helmet, Item chest, Item legs, Item boots) { //for brainlets (me) to add more armorsets later when i forget about how this works + entity.setCurrentItemOrArmor(4, new ItemStack(helmet)); //p_70062_1_ is the slot number + entity.setCurrentItemOrArmor(3, new ItemStack(chest)); + entity.setCurrentItemOrArmor(2, new ItemStack(legs)); + entity.setCurrentItemOrArmor(1, new ItemStack(boots)); + } + + public static void assignItemsToEntity(EntityLivingBase entity, Map> slotPools, Random rand) { + for (Map.Entry> entry : slotPools.entrySet()) { + int slot = entry.getKey(); + List pool = entry.getValue(); + + WeightedRandomObject choice = (WeightedRandomObject) WeightedRandom.getRandomItem(rand, pool); //NullPointerException sludge fix + if (choice == null) { + continue; + } + + ItemStack stack = choice.asStack(); + if (stack == null || stack.getItem() == null) { + continue; + } + + if (stack.getItem() == ModItems.gas_mask_m65 //eyesore + || stack.getItem() == ModItems.gas_mask_olde + || stack.getItem() == ModItems.gas_mask_mono) { + ArmorUtil.installGasMaskFilter(stack, new ItemStack(ModItems.gas_mask_filter)); + } + + entity.setCurrentItemOrArmor(slot, stack); + + //Give skeleton AI if it has a gun + if (slot == 0 && entity instanceof EntitySkeleton && pool == slotPools.get(0)) { + addFireTask((EntityLiving) entity); + } + } + } + + // these fucking tasks keep stacking on top of themselves + public static void addFireTask(EntityLiving entity) { + entity.setEquipmentDropChance(0, 0); // Prevent dropping guns + + for(Object entry : entity.tasks.taskEntries) { + EntityAITasks.EntityAITaskEntry task = (EntityAITasks.EntityAITaskEntry) entry; + if(task.action instanceof EntityAIFireGun) return; + } + + entity.tasks.addTask(3, new EntityAIFireGun(entity)); + } +} diff --git a/src/main/java/com/hbm/world/gen/util/LogicBlockActions.java b/src/main/java/com/hbm/world/gen/util/LogicBlockActions.java new file mode 100644 index 000000000..2b3682c7c --- /dev/null +++ b/src/main/java/com/hbm/world/gen/util/LogicBlockActions.java @@ -0,0 +1,269 @@ +package com.hbm.world.gen.util; + +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; +import com.hbm.items.ItemEnums; +import com.hbm.items.ModItems; +import com.hbm.tileentity.TileEntityDoorGeneric; +import com.hbm.tileentity.machine.storage.TileEntityCrateBase; +import com.hbm.util.ContaminationUtil; +import com.hbm.util.MobUtil; +import com.hbm.util.Vec3NT; +import com.hbm.world.WorldUtil; +import net.minecraft.block.Block; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.effect.EntityLightningBolt; +import net.minecraft.entity.monster.EntityZombie; +import net.minecraft.init.Blocks; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.*; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +import java.util.*; +import java.util.function.Consumer; + +public class LogicBlockActions { + + public static LinkedHashMap> actions = new LinkedHashMap<>(); + + 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) { + tile.player = world.getClosestPlayer(x,y,z, 25); + if (tile.timer == 0) { + Vec3NT vec = new Vec3NT(20, 0, 0); + for (int i = 0; i < 10; i++) { + + if(vec.xCoord > 8) vec.xCoord += world.rand.nextInt(10) - 5; + + EntityUndeadSoldier mob = new EntityUndeadSoldier(world); + for (int j = 0; j < 7; j++) { + mob.setPositionAndRotation(x + 0.5 + vec.xCoord, world.getHeightValue((int) (x + 0.5 + vec.xCoord),(int) (z + 0.5 + vec.zCoord)), z + 0.5 + vec.zCoord, i * 36F, 0); + if (mob.getCanSpawnHere()) { + mob.onSpawnWithEgg(null); + if(tile.player != null){ + mob.setTarget(tile.player); + } + world.spawnEntityInWorld(mob); + break; + } + } + vec.rotateAroundYDeg(36D); + } + } + } + if (tile.phase > 2) { + TileEntity te = world.getTileEntity(x, y + 18, z); + if (te instanceof BlockSkeletonHolder.TileEntitySkeletonHolder) { + BlockSkeletonHolder.TileEntitySkeletonHolder skeleton = (BlockSkeletonHolder.TileEntitySkeletonHolder) te; + if (world.rand.nextInt(5) == 0) { + skeleton.item = new ItemStack(ModItems.item_secret, 1, ItemEnums.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); + } + }; + + public static Consumer COLLAPSE_ROOF_RAD_5 = (tile) -> { + World world = tile.getWorldObj(); + int x = tile.xCoord; + int y = tile.yCoord; + int z = tile.zCoord; + + if(tile.phase == 0) return; + + //from explosionChaos because i cannot be assed + int r = 4; + int r2 = r * r; + int r22 = r2 / 2; + + for (int xx = -r; xx < r; xx++) { + int X = xx + x; + int XX = xx * xx; + for (int yy = -r; yy < r; yy++) { + int Y = yy + y; + int YY = XX + yy * yy; + for (int zz = -r; zz < r; zz++) { + int Z = zz + z; + int ZZ = YY + zz * zz; + if (ZZ < r22) { + + if (world.getBlock(X, Y, Z).getExplosionResistance(null) <= 70) { + EntityFallingBlockNT entityfallingblock = new EntityFallingBlockNT(world, X + 0.5, Y + 0.5, Z + 0.5, world.getBlock(X, Y, Z), world.getBlockMetadata(X, Y, Z)); + world.spawnEntityInWorld(entityfallingblock); + } + } + } + } + } + world.setBlock(x, y, z, ModBlocks.block_steel); + + }; + + public static Consumer FODDER_WAVE = (tile) -> { + World world = tile.getWorldObj(); + int x = tile.xCoord; + int y = tile.yCoord; + int z = tile.zCoord; + if (tile.phase == 1) { + Vec3NT vec = new Vec3NT(5, 0, 0); + for (int i = 0; i < 10; i++) { + EntityZombie mob = new EntityZombie(world); + mob.setPositionAndRotation(x + 0.5 + vec.xCoord, world.getHeightValue(x,z), z + 0.5 + vec.zCoord, i * 36F, 0); + MobUtil.assignItemsToEntity(mob, MobUtil.slotPoolAdv, new Random()); + world.spawnEntityInWorld(mob); + + vec.rotateAroundYDeg(36D); + } + world.setBlock(x, y, z, ModBlocks.block_steel); + } + }; + + public static Consumer PUZZLE_TEST = (tile) -> { + World world = tile.getWorldObj(); + int x = tile.xCoord; + int y = tile.yCoord; + int z = tile.zCoord; + + if(tile.phase == 2){ + world.setBlock(x,y,z, ModBlocks.crate_steel); + + EntityLightningBolt blitz = new EntityLightningBolt(world, x, world.getHeightValue(x, z) + 2, z); + world.spawnEntityInWorld(blitz); + + TileEntityCrateBase crate = (TileEntityCrateBase) world.getTileEntity(x,y,z); + ((IInventory)crate).setInventorySlotContents(15, new ItemStack(ModItems.gun_bolter)); + } + }; + + public static Consumer MISSILE_STRIKE = (tile) -> { + World world = tile.getWorldObj(); + int x = tile.xCoord; + int y = tile.yCoord; + int z = tile.zCoord; + + if(tile.phase != 1) return; + + world.getClosestPlayer(x,y,z, 25).addChatMessage(new ChatComponentText(EnumChatFormatting.LIGHT_PURPLE + "[COMMAND UNIT]"+ EnumChatFormatting.RESET + " Missile Fired")); + + ForgeDirection parallel = tile.direction.getRotation(ForgeDirection.UP); + + EntityMissileTier2.EntityMissileStrong missile = + new EntityMissileTier2.EntityMissileStrong( + world, + x + tile.direction.offsetX * 300, + 200, + z + tile.direction.offsetZ * 300, + x + parallel.offsetX * 30 + tile.direction.offsetX * 30, + z + parallel.offsetZ * 30 + tile.direction.offsetZ * 30); + WorldUtil.loadAndSpawnEntityInWorld(missile); + + world.setBlock(x,y,z, ModBlocks.block_electrical_scrap); + }; + + public static Consumer RAD_CONTAINMENT_SYSTEM = (tile) -> { + World world = tile.getWorldObj(); + int x = tile.xCoord; + int y = tile.yCoord; + int z = tile.zCoord; + + ForgeDirection direction = tile.direction.getOpposite(); + ForgeDirection rot = direction.getRotation(ForgeDirection.UP); + + AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(x - rot.offsetX, y - 1, z - rot.offsetZ, x + rot.offsetX + direction.offsetX * 15, y + 1, z + rot.offsetZ + direction.offsetZ * 15).expand(2,2,2); + + List entities = world.getEntitiesWithinAABB(EntityLivingBase.class, bb); + + for(EntityLivingBase e : entities) { + + Vec3 vec = Vec3.createVectorHelper(e.posX - (x + 0.5), (e.posY + e.getEyeHeight()) - (y + 0.5), e.posZ - (z + 0.5)); + double len = vec.lengthVector(); + vec = vec.normalize(); + + len = Math.max(len,1D); + + float res = 0; + + for(int i = 1; i < len; i++) { + + int ix = (int)Math.floor(x + 0.5 + vec.xCoord * i); + int iy = (int)Math.floor(y + 0.5 + vec.yCoord * i); + int iz = (int)Math.floor(z + 0.5 + vec.zCoord * i); + + res += world.getBlock(ix, iy, iz).getExplosionResistance(null); + } + + if(res < 1) + res = 1; + + float eRads = 100F; + eRads /= (float)res; + eRads /= (float)(len * len); + + ContaminationUtil.contaminate(e, ContaminationUtil.HazardType.RADIATION, ContaminationUtil.ContaminationType.HAZMAT2, eRads); + } + + if (tile.phase == 2 && tile.timer > 40){ + world.getClosestPlayer(x,y,z, 25).addChatMessage(new ChatComponentText( + EnumChatFormatting.LIGHT_PURPLE + "[RAD CONTAINMENT SYSTEM]" + + EnumChatFormatting.RESET + " Diagnostics found containment failure, commencing lockdown")); + + for(int i = 1; i < 20; i++) { + int checkX, checkY, checkZ; + checkX = x + direction.offsetX * i; + checkY = y + 1; + checkZ = z + direction.offsetZ * i; + Block block = world.getBlock(checkX, checkY,checkZ); + TileEntity te = null; + if(block instanceof BlockDummyable){ + int[] coreCoords = ((BlockDummyable) block).findCore(world,checkX,checkY,checkZ); + te = world.getTileEntity(coreCoords[0], coreCoords[1], coreCoords[2]); + } + + if (te instanceof TileEntityDoorGeneric) { + TileEntityDoorGeneric door = (TileEntityDoorGeneric) te; + door.setPins(456); + door.close(); + door.lock(); + break; + } + } + + tile.phase = 3; + } + }; + + public static List getActionNames(){ + return new ArrayList<>(actions.keySet()); + } + + //register new actions here + static{ + //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/LogicBlockConditions.java b/src/main/java/com/hbm/world/gen/util/LogicBlockConditions.java new file mode 100644 index 000000000..5065a38fd --- /dev/null +++ b/src/main/java/com/hbm/world/gen/util/LogicBlockConditions.java @@ -0,0 +1,98 @@ +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 net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.function.Function; + +public class LogicBlockConditions { + + 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 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; + + boolean aoeCheck = !world.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y - 2, z + 1).expand(10, 10, 10)).isEmpty(); + if(tile.phase == 0) { + if(world.getTotalWorldTime() % 20 != 0) return false; + return aoeCheck; + } + 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() && aoeCheck; + } + return false; + }; + + public static Function PLAYER_CUBE_5 = (tile) -> { + World world = tile.getWorldObj(); + int x = tile.xCoord; + int y = tile.yCoord; + int z = tile.zCoord; + 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) -> { + World world = tile.getWorldObj(); + int x = tile.xCoord; + int y = tile.yCoord; + int z = tile.zCoord; + + return world.isBlockIndirectlyGettingPowered(x,y,z); + }; + + public static Function PUZZLE_TEST = (tile) -> { + World world = tile.getWorldObj(); + int x = tile.xCoord; + int y = tile.yCoord; + int z = tile.zCoord; + + if(tile.phase == 0 && world.isBlockIndirectlyGettingPowered(x,y,z)){ + world.getClosestPlayer(x,y,z, 25).addChatMessage(new ChatComponentText("Find a " + EnumChatFormatting.GOLD + "great" + EnumChatFormatting.RESET + " ancient weapon, of questionable use in the modern age")); + world.setBlock(x,y + 1,z, ModBlocks.pedestal); + return true; + } + + TileEntity pedestal = world.getTileEntity(x,y + 1,z); + + return tile.phase == 1 + && pedestal instanceof BlockPedestal.TileEntityPedestal + && ((BlockPedestal.TileEntityPedestal) pedestal).item != null + && ((BlockPedestal.TileEntityPedestal) pedestal).item.getItem() == ModItems.big_sword; + }; + + public static List getConditionNames(){ + return new ArrayList<>(conditions.keySet()); + } + + //register new conditions here + static { + //example conditions + conditions.put("EMPTY", EMPTY); + conditions.put("ABERRATOR", ABERRATOR); + conditions.put("PLAYER_CUBE_5", PLAYER_CUBE_5); + conditions.put("REDSTONE", REDSTONE); + conditions.put("PUZZLE_TEST", PUZZLE_TEST); + } + +} diff --git a/src/main/java/com/hbm/world/gen/util/LogicBlockInteractions.java b/src/main/java/com/hbm/world/gen/util/LogicBlockInteractions.java new file mode 100644 index 000000000..decf997a6 --- /dev/null +++ b/src/main/java/com/hbm/world/gen/util/LogicBlockInteractions.java @@ -0,0 +1,72 @@ +package com.hbm.world.gen.util; + +import com.hbm.blocks.generic.LogicBlock; +import com.hbm.blocks.generic.LogicBlock.TileEntityLogicBlock; +import com.hbm.items.ModItems; +import com.hbm.potion.HbmPotion; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; + +import java.util.ArrayList; +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 LogicBlockInteractions { + + /**Consumer consists of world instance, tile entity instance, three ints for coordinates, one int for block side, and player instance, + * in that order **/ + public static LinkedHashMap> interactions = new LinkedHashMap<>(); + + public static Consumer TEST = (array) -> { + World world = (World) array[0]; + 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(logic.phase > 1) return; + + if(player.getHeldItem() != null) + player.getHeldItem().stackSize--; + + logic.phase++; + }; + + public static Consumer RAD_CONTAINMENT_SYSTEM = (array) -> { + LogicBlock.TileEntityLogicBlock logic = (LogicBlock.TileEntityLogicBlock) array[1]; + EntityPlayer player = (EntityPlayer) array[5]; + + if(player.getHeldItem() != null && player.getHeldItem().getItem() == ModItems.key){ + player.getHeldItem().stackSize--; + player.addChatMessage(new ChatComponentText( + EnumChatFormatting.LIGHT_PURPLE + "[RAD CONTAINMENT SYSTEM]" + + 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)); + logic.phase = 2; + logic.timer = 0; + } + }; + + + + public static List getInteractionNames(){ + return new ArrayList<>(interactions.keySet()); + } + + //register new interactions here + static{ + interactions.put("TEST", TEST); + interactions.put("RADAWAY_INJECTOR", RAD_CONTAINMENT_SYSTEM); + } + + + +} diff --git a/src/main/resources/assets/hbm/lang/en_US.lang b/src/main/resources/assets/hbm/lang/en_US.lang index 74c5a343b..c5fd461eb 100644 --- a/src/main/resources/assets/hbm/lang/en_US.lang +++ b/src/main/resources/assets/hbm/lang/en_US.lang @@ -5279,6 +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.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 @@ -6061,6 +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_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_logic.png b/src/main/resources/assets/hbm/textures/blocks/wand_logic.png new file mode 100644 index 000000000..4561c8e4e Binary files /dev/null and b/src/main/resources/assets/hbm/textures/blocks/wand_logic.png differ diff --git a/src/main/resources/assets/hbm/textures/blocks/wand_logic_top.png b/src/main/resources/assets/hbm/textures/blocks/wand_logic_top.png new file mode 100644 index 000000000..65e3106a9 Binary files /dev/null and b/src/main/resources/assets/hbm/textures/blocks/wand_logic_top.png differ