From 085bde4b9952a519da21a7aa2de3426a8c7afcf8 Mon Sep 17 00:00:00 2001 From: Bob Date: Mon, 29 Apr 2024 21:57:18 +0200 Subject: [PATCH] ICF block stuff --- changelog | 1 + .../java/com/hbm/blocks/machine/BlockICF.java | 149 ++++++++++++++++- .../blocks/machine/MachineICFController.java | 158 +++++++++++++++++- .../java/com/hbm/tileentity/TileMappings.java | 1 + .../machine/TileEntityICFController.java | 48 ++++++ 5 files changed, 352 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/hbm/tileentity/machine/TileEntityICFController.java diff --git a/changelog b/changelog index 334b59817..677879017 100644 --- a/changelog +++ b/changelog @@ -19,6 +19,7 @@ * The loot pool for meteorite treasure blocks has been updated * Treasures are no longer senselessly progression breaking, radioactive or plain stupid (whole-ass machines inside meteorites) * The treasure now consists of mainly some rarer earlygame ingots, circuits, some gear, a small selection of armor mods and alexandrite (rare) +* Schraranium processing now yields neptunium as a byproduct instead of plutonium, making neptunium easier to automate outside of the cyclotron ## Fixed * Fixed DFC receivers not outputting power diff --git a/src/main/java/com/hbm/blocks/machine/BlockICF.java b/src/main/java/com/hbm/blocks/machine/BlockICF.java index 07bb53a6a..4daee8fa0 100644 --- a/src/main/java/com/hbm/blocks/machine/BlockICF.java +++ b/src/main/java/com/hbm/blocks/machine/BlockICF.java @@ -7,14 +7,18 @@ import com.hbm.lib.RefStrings; import com.hbm.render.block.ct.CT; import com.hbm.render.block.ct.CTStitchReceiver; import com.hbm.render.block.ct.IBlockCT; +import com.hbm.tileentity.machine.TileEntityICFController; +import api.hbm.energymk2.IEnergyReceiverMK2; 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.client.renderer.texture.IIconRegister; +import net.minecraft.init.Blocks; import net.minecraft.item.Item; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; @@ -44,7 +48,7 @@ public class BlockICF extends BlockContainer implements IBlockCT { @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister reg) { super.registerBlockIcons(reg); - this.iconPort = reg.registerIcon(RefStrings.MODID + ":icf_casing_port"); + this.iconPort = reg.registerIcon(RefStrings.MODID + ":icf_block_port"); this.rec = IBlockCT.primeReceiver(reg, this.blockIcon.getIconName(), this.blockIcon); this.recPort = IBlockCT.primeReceiver(reg, this.iconPort.getIconName(), this.iconPort); } @@ -65,8 +69,147 @@ public class BlockICF extends BlockContainer implements IBlockCT { public TileEntity createNewTileEntity(World world, int meta) { return new TileEntityBlockICF(); } - - public static class TileEntityBlockICF extends TileEntity { + + @Override + public void breakBlock(World world, int x, int y, int z, Block block, int meta) { + TileEntity tile = world.getTileEntity(x, y, z); + + if(tile instanceof TileEntityBlockICF) { + TileEntityBlockICF icf = (TileEntityBlockICF) tile; + world.removeTileEntity(x, y, z); + if(icf.block != null) { + world.setBlock(x, y, z, icf.block, icf.meta, 3); + TileEntity controller = world.getTileEntity(icf.coreX, icf.coreY, icf.coreZ); + + if(controller instanceof TileEntityICFController) { + ((TileEntityICFController) controller).assembled = false; + } + } + } else { + world.removeTileEntity(x, y, z); + } + super.breakBlock(world, x, y, z, block, meta); + } + + public static class TileEntityBlockICF extends TileEntity implements IEnergyReceiverMK2 { + + public Block block; + public int meta; + public int coreX; + public int coreY; + public int coreZ; + + @Override + public void updateEntity() { + + if(!worldObj.isRemote) { + + if(worldObj.getTotalWorldTime() % 20 == 0 && block != null) { + + TileEntityICFController controller = getCore(); + + if(controller != null) { + if(!controller.assembled) { + this.getBlockType().breakBlock(worldObj, xCoord, yCoord, zCoord, this.getBlockType(), this.getBlockMetadata()); + } + } else if(worldObj.getChunkProvider().chunkExists(coreX >> 4, coreZ >> 4)) { + this.getBlockType().breakBlock(worldObj, xCoord, yCoord, zCoord, this.getBlockType(), this.getBlockMetadata()); + } + } + } + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + + block = Block.getBlockById(nbt.getInteger("block")); + if(block != Blocks.air) { + meta = nbt.getInteger("meta"); + coreX = nbt.getInteger("cX"); + coreY = nbt.getInteger("cY"); + coreZ = nbt.getInteger("cZ"); + } else { + block = null; + } + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + + if(block != null) { + nbt.setInteger("block", Block.getIdFromBlock(block)); + nbt.setInteger("meta", meta); + nbt.setInteger("cX", coreX); + nbt.setInteger("cY", coreY); + nbt.setInteger("cZ", coreZ); + } + } + + @Override + public void markDirty() { + if(this.worldObj != null) { + this.worldObj.markTileEntityChunkModified(this.xCoord, this.yCoord, this.zCoord, this); + } + } + + public TileEntityICFController cachedCore; + + protected TileEntityICFController getCore() { + + if(cachedCore != null && !cachedCore.isInvalid()) return cachedCore; + + if(worldObj.getChunkProvider().chunkExists(coreX >> 4, coreZ >> 4)) { + + TileEntity tile = worldObj.getTileEntity(coreX, coreY, coreZ); + if(tile instanceof TileEntityICFController) { + TileEntityICFController controller = (TileEntityICFController) tile; + cachedCore = controller; + return controller; + } + } + + return null; + } + + @Override public long getPower() { + if(this.getBlockMetadata() != 1) return 0; + if(block == null) return 0; + TileEntityICFController controller = this.getCore(); + if(controller != null) return controller.getPower(); + + return 0; + } + + @Override public void setPower(long power) { + if(this.getBlockMetadata() != 1) return; + if(block == null) return; + TileEntityICFController controller = this.getCore(); + if(controller != null) controller.setPower(power); + } + + @Override public long getMaxPower() { + if(this.getBlockMetadata() != 1) return 0; + if(block == null) return 0; + TileEntityICFController controller = this.getCore(); + if(controller != null) return controller.getMaxPower(); + + return 0; + } + + public boolean isLoaded = true; + + @Override + public boolean isLoaded() { + return isLoaded; + } + + @Override + public void onChunkUnload() { + super.onChunkUnload(); + this.isLoaded = false; + } } } diff --git a/src/main/java/com/hbm/blocks/machine/MachineICFController.java b/src/main/java/com/hbm/blocks/machine/MachineICFController.java index ba1487f40..da2d80619 100644 --- a/src/main/java/com/hbm/blocks/machine/MachineICFController.java +++ b/src/main/java/com/hbm/blocks/machine/MachineICFController.java @@ -1,18 +1,34 @@ package com.hbm.blocks.machine; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map.Entry; + +import com.hbm.blocks.ModBlocks; +import com.hbm.blocks.machine.BlockICF.TileEntityBlockICF; +import com.hbm.blocks.machine.BlockICFLaserComponent.EnumICFPart; import com.hbm.lib.RefStrings; +import com.hbm.packet.AuxParticlePacketNT; +import com.hbm.packet.PacketDispatcher; +import com.hbm.tileentity.machine.TileEntityICFController; +import com.hbm.util.fauxpointtwelve.BlockPos; 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.client.renderer.texture.IIconRegister; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; public class MachineICFController extends BlockContainer { @@ -24,8 +40,8 @@ public class MachineICFController extends BlockContainer { } @Override - public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) { - return null; + public TileEntity createNewTileEntity(World world, int meta) { + return new TileEntityICFController(); } @Override @@ -50,4 +66,142 @@ public class MachineICFController extends BlockContainer { if(i == 2) world.setBlockMetadataWithNotify(x, y, z, 3, 2); if(i == 3) world.setBlockMetadataWithNotify(x, y, z, 4, 2); } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { + + if(world.isRemote) { + return true; + } else if(!player.isSneaking()) { + + TileEntityICFController controller = (TileEntityICFController) world.getTileEntity(x, y, z); + + if(!controller.assembled) { + assemble(world, x, y, z, player); + } + + return true; + } else { + return false; + } + } + + private static HashMap assembly = new HashMap(); + private static HashSet casings = new HashSet(); + private static HashSet ports = new HashSet(); + private static HashSet cells = new HashSet(); + private static HashSet emitters = new HashSet(); + private static HashSet capacitors = new HashSet(); + private static HashSet turbochargers = new HashSet(); + private static boolean errored; + private static final int maxSize = 1024; + + public void assemble(World world, int x, int y, int z, EntityPlayer player) { + assembly.clear(); + casings.clear(); + ports.clear(); + cells.clear(); + emitters.clear(); + capacitors.clear(); + turbochargers.clear(); + assembly.put(new BlockPos(x, y, z), 0); + + ForgeDirection dir = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z)).getOpposite(); + + errored = false; + floodFill(world, x + dir.offsetX, y, z + dir.offsetZ, player); + assembly.remove(new BlockPos(x, y, z)); + + TileEntityICFController controller = (TileEntityICFController) world.getTileEntity(x, y, z); + + if(!errored) { + + for(Entry entry : assembly.entrySet()) { + + BlockPos pos = entry.getKey(); + + if(ports.contains(pos)) { + world.setBlock(pos.getX(), pos.getY(), pos.getZ(), ModBlocks.icf_block, 1, 3); + } else { + world.setBlock(pos.getX(), pos.getY(), pos.getZ(), ModBlocks.icf_block, 0, 3); + } + + TileEntityBlockICF icf = (TileEntityBlockICF) world.getTileEntity(pos.getX(), pos.getY(), pos.getZ()); + icf.block = ModBlocks.icf_laser_component; + icf.meta = entry.getValue(); + icf.coreX = x; + icf.coreY = y; + icf.coreZ = z; + icf.markDirty(); + } + } + controller.assembled = !errored; + + assembly.clear(); + casings.clear(); + ports.clear(); + cells.clear(); + emitters.clear(); + capacitors.clear(); + turbochargers.clear(); + } + + private void floodFill(World world, int x, int y, int z, EntityPlayer player) { + + BlockPos pos = new BlockPos(x, y, z); + + if(assembly.containsKey(pos)) return; + if(assembly.size() >= maxSize) { + errored = true; + sendError(world, x, y, z, "Max size exceeded", player); + return; + } + + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + + boolean validCasing = false; + boolean validCore = false; + + if(block == ModBlocks.icf_laser_component) { + if(meta == EnumICFPart.CASING.ordinal()) { casings.add(pos); validCasing = true; } + if(meta == EnumICFPart.PORT.ordinal()) { ports.add(pos); validCasing = true; } + if(meta == EnumICFPart.CELL.ordinal()) { cells.add(pos); validCore = true; } + if(meta == EnumICFPart.EMITTER.ordinal()) { emitters.add(pos); validCore = true; } + if(meta == EnumICFPart.CAPACITOR.ordinal()) { capacitors.add(pos); validCore = true; } + if(meta == EnumICFPart.TURBO.ordinal()) { turbochargers.add(pos); validCore = true; } + } + + if(validCasing) { + assembly.put(pos, meta); + return; + } + + if(validCore) { + assembly.put(pos, meta); + floodFill(world, x + 1, y, z, player); + floodFill(world, x - 1, y, z, player); + floodFill(world, x, y + 1, z, player); + floodFill(world, x, y - 1, z, player); + floodFill(world, x, y, z + 1, player); + floodFill(world, x, y, z - 1, player); + return; + } + + sendError(world, x, y, z, "Non-laser block", player); + errored = true; + } + + private void sendError(World world, int x, int y, int z, String message, EntityPlayer player) { + + if(player instanceof EntityPlayerMP) { + NBTTagCompound data = new NBTTagCompound(); + data.setString("type", "marker"); + data.setInteger("color", 0xff0000); + data.setInteger("expires", 5_000); + data.setDouble("dist", 128D); + if(message != null) data.setString("label", message); + PacketDispatcher.wrapper.sendTo(new AuxParticlePacketNT(data, x, y, z), (EntityPlayerMP) player); + } + } } diff --git a/src/main/java/com/hbm/tileentity/TileMappings.java b/src/main/java/com/hbm/tileentity/TileMappings.java index 6722092e2..a6d60d8b8 100644 --- a/src/main/java/com/hbm/tileentity/TileMappings.java +++ b/src/main/java/com/hbm/tileentity/TileMappings.java @@ -162,6 +162,7 @@ public class TileMappings { put(TileEntityMachineMiniRTG.class, "tileentity_mini_rtg"); put(TileEntityITER.class, "tileentity_iter"); put(TileEntityBlockICF.class, "tileentity_block_icf"); + put(TileEntityICFController.class, "tileentity_icf_controller"); put(TileEntityICF.class, "tileentity_icf"); put(TileEntityMachinePlasmaHeater.class, "tileentity_plasma_heater"); put(TileEntityMachineFENSU.class, "tileentity_fensu"); diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityICFController.java b/src/main/java/com/hbm/tileentity/machine/TileEntityICFController.java new file mode 100644 index 000000000..49dfa173e --- /dev/null +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityICFController.java @@ -0,0 +1,48 @@ +package com.hbm.tileentity.machine; + +import java.util.ArrayList; +import java.util.List; + +import com.hbm.tileentity.TileEntityTickingBase; +import com.hbm.util.fauxpointtwelve.BlockPos; + +import api.hbm.energymk2.IEnergyReceiverMK2; + +public class TileEntityICFController extends TileEntityTickingBase implements IEnergyReceiverMK2 { + + public long power; + + public int cellCount; + public int emitterCount; + public int capacitorCount; + public int turbochargerCount; + + protected List ports = new ArrayList(); + + public boolean assembled; + + @Override + public String getInventoryName() { + return "container.icfController"; + } + + @Override + public void updateEntity() { + + } + + @Override + public long getPower() { + return power; + } + + @Override + public void setPower(long power) { + this.power = power; + } + + @Override + public long getMaxPower() { + return capacitorCount * 1_000_000 + turbochargerCount * 2_500_000; //TEMP + } +}