Added IBlowable for fan; created TE for a piston-based inserter (IInsertable). The former will improve cooling for pile setups and the latter will allow for automation, in combination with comparator output for pile fuel.
This commit is contained in:
Vaern 2023-05-13 22:34:48 -07:00
parent c7f28e8853
commit f52eb08301
9 changed files with 274 additions and 13 deletions

View File

@ -0,0 +1,10 @@
package api.hbm.block;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public interface IBlowable { //sloppy toppy
/** Called server-side when a fan blows on an IBlowable in range every tick. */
public void applyFan(World world, int x, int y, int z, ForgeDirection dir, int dist);
}

View File

@ -0,0 +1,10 @@
package api.hbm.block;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public interface IInsertable { //uwu
public boolean insertItem(World world, int x, int y, int z, ForgeDirection dir, ItemStack stack);
}

View File

@ -2,9 +2,11 @@ package com.hbm.blocks.machine;
import java.util.List;
import api.hbm.block.IBlowable;
import api.hbm.block.IToolable;
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.BlockPistonBase;
import net.minecraft.block.material.Material;
@ -79,7 +81,13 @@ public class MachineFan extends BlockContainer implements IToolable {
double push = 0.1;
for(int i = 1; i <= range; i++) {
if(worldObj.getBlock(xCoord + dir.offsetX * i, yCoord + dir.offsetY * i, zCoord + dir.offsetZ * i).isNormalCube()) {
Block block = worldObj.getBlock(xCoord + dir.offsetX * i, yCoord + dir.offsetY * i, zCoord + dir.offsetZ * i);
boolean blowable = block instanceof IBlowable;
if(block.isNormalCube() || blowable) {
if(!worldObj.isRemote && blowable)
((IBlowable) block).applyFan(worldObj, xCoord + dir.offsetX * i, yCoord + dir.offsetY * i, zCoord + dir.offsetZ * i, dir, i);
break;
}

View File

@ -0,0 +1,210 @@
package com.hbm.blocks.machine;
import com.hbm.blocks.BlockContainerBase;
import com.hbm.tileentity.INBTPacketReceiver;
import api.hbm.block.IInsertable;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class PistonInserter extends BlockContainerBase {
public PistonInserter() {
super(Material.iron);
}
@Override
public TileEntity createNewTileEntity(World world, int meta) {
return new TileEntityPistonInserter();
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block neighbor) {
this.updateState(world, x, y, z);
}
protected void updateState(World world, int x, int y, int z) {
if(!world.isRemote) {
ForgeDirection dir = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z));
if(world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ).isNormalCube())
return; //no obstructions allowed!
if(checkRedstone(world, x, y, z)) { //if necessary, add lastState (if block updates are too unreliable).
TileEntityPistonInserter piston = (TileEntityPistonInserter)world.getTileEntity(x, y, z);
if(piston.extend <= 0)
piston.isRetracting = false;
}
}
}
protected boolean checkRedstone(World world, int x, int y, int z) {
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if(world.getIndirectPowerOutput(x, y, z, dir.ordinal()))
return true;
}
return false;
}
// $%&#$&
// %$&&@$%%#%
//______ $%@--$@@%&$%$
// | %/ *--$#@&&$$
// | / --__ %$%@$&
// | (----^`--- $@##%
// | /___\ `-----*#@$
// | /(()_) / /___\ /__
// | / \___// (()_) //-,|
// | /____|_ / \___// )_/
// | \____/ `^-___|___/ |
// | \/ \____/ /_-^-.
// | / _-' |___. \_
// | / _-' / `\ \\___
// | `'\____~~+~^/ _)/ \____
// | \`----' | __/ _)
// | /( /~-' ,-' |
// | / `| | / |
// | / ( ) / `)
// | / `-==-' | |
// | / /| | |
// | / / \ | |
// | / / | | |
// | / / \ _____,.____| |
// | / _ / |<`____, ____,| |
// | / / \_ / _ | <_____/ | )
// | / / ^/,^=-~---~' `z---..._______/ |
// |--' / /| |/ .^ ,^\ \ )
// | |_|| || |(_( ) | |
// | \_/`-``-`----'___/_____ |
// |___..---' _|____`-----..-----'\
// |_____________________| @ | )
// average coding session involving tile entities
public static class TileEntityPistonInserter extends TileEntity implements IInventory, INBTPacketReceiver {
public ItemStack slot;
public int extend;
public static final int maxExtend = 25;
public boolean isRetracting;
public int delay;
private int lastState;
public TileEntityPistonInserter() { }
@Override
public void updateEntity() { //what is this amalgamation
if(!worldObj.isRemote) {
if(delay <= 0) {
if(this.isRetracting && this.extend > 0) {
this.extend--;
} else if(!this.isRetracting) {
this.extend++;
if(this.extend >= this.maxExtend) {
worldObj.playSoundEffect(xCoord, yCoord, zCoord, "hbm:block.pressOperate", 1.5F, 1.0F);
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata());
Block b = worldObj.getBlock(xCoord + dir.offsetX * 2, yCoord + dir.offsetY * 2, zCoord + dir.offsetZ * 2);
if(b instanceof IInsertable && ((IInsertable) b).insertItem(worldObj, xCoord + dir.offsetX * 2, yCoord + dir.offsetY * 2, zCoord + dir.offsetZ * 2, dir, slot)) {
this.decrStackSize(0, 1);
}
this.isRetracting = true;
this.delay = 5;
}
}
} else {
delay--;
}
NBTTagCompound data = new NBTTagCompound();
data.setInteger("extend", extend);
if(this.slot != null) {
NBTTagCompound stack = new NBTTagCompound();
slot.writeToNBT(stack);
data.setTag("stack", stack);
}
INBTPacketReceiver.networkPack(this, data, 25);
}
}
@Override
public void networkUnpack(NBTTagCompound nbt) {
this.extend = nbt.getInteger("extend");
if(nbt.hasKey("stack")) {
NBTTagCompound stack = nbt.getCompoundTag("stack");
this.slot = ItemStack.loadItemStackFromNBT(stack);
} else
this.slot = null;
}
/* BS inventory stuff */
@Override public int getSizeInventory() { return 1; }
@Override public ItemStack getStackInSlot(int slot) { return this.slot; }
@Override
public ItemStack decrStackSize(int slot, int amount) {
if(this.slot != null) {
if(this.slot.stackSize <= amount) {
ItemStack stack = this.slot;
this.slot = null;
return stack;
}
ItemStack stack = this.slot.splitStack(amount);
if(this.slot.stackSize == 0)
this.slot = null;
return stack;
}
return null;
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) { return null; }
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
this.slot = stack;
if(stack != null && stack.stackSize > this.getInventoryStackLimit())
stack.stackSize = this.getInventoryStackLimit();
}
@Override public String getInventoryName() { return null; }
@Override public boolean hasCustomInventoryName() { return false; }
@Override public int getInventoryStackLimit() { return 1; }
@Override public boolean isUseableByPlayer(EntityPlayer player) { return false; }
@Override public void openInventory() {}
@Override public void closeInventory() {}
@Override public boolean isItemValidForSlot(int slot, ItemStack stack) { return true; }
}
}

View File

@ -64,4 +64,5 @@ public class BlockGraphiteBreedingFuel extends BlockGraphiteDrilledTE implements
protected Item getInsertedItem() {
return ModItems.pile_rod_lithium;
}
}

View File

@ -5,6 +5,7 @@ import com.hbm.items.ModItems;
import com.hbm.lib.RefStrings;
import com.hbm.tileentity.machine.pile.TileEntityPileFuel;
import api.hbm.block.IBlowable;
import api.hbm.block.IToolable;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -19,7 +20,7 @@ import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class BlockGraphiteFuel extends BlockGraphiteDrilledTE implements IToolable {
public class BlockGraphiteFuel extends BlockGraphiteDrilledTE implements IToolable, IBlowable {
@Override
public TileEntity createNewTileEntity(World world, int mets) {
@ -68,4 +69,10 @@ public class BlockGraphiteFuel extends BlockGraphiteDrilledTE implements IToolab
protected Item getInsertedItem(int meta) {
return (meta & 8) == 8 ? ModItems.pile_rod_pu239 : ModItems.pile_rod_uranium;
}
@Override
public void applyFan(World world, int x, int y, int z, ForgeDirection dir, int dist) {
TileEntityPileFuel pile = (TileEntityPileFuel) world.getTileEntity(x, y, z);
pile.heat -= pile.heat * 0.025;
}
}

View File

@ -4,6 +4,7 @@ import java.util.List;
import java.util.Random;
import com.hbm.blocks.ModBlocks;
import com.hbm.main.MainRegistry;
import com.hbm.util.ContaminationUtil;
import com.hbm.util.ContaminationUtil.ContaminationType;
import com.hbm.util.ContaminationUtil.HazardType;
@ -11,6 +12,7 @@ import com.hbm.util.ContaminationUtil.HazardType;
import api.hbm.block.IPileNeutronReceiver;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Vec3;
@ -21,11 +23,8 @@ public abstract class TileEntityPileBase extends TileEntity {
public abstract void updateEntity();
protected void castRay(int flux, int range) {
Random rand = worldObj.rand;
int[] vecVals = { 0, 0, 0,};
vecVals[rand.nextInt(3)] = 1;
Vec3 vec = Vec3.createVectorHelper(vecVals[0], vecVals[1], vecVals[2]);
Vec3 vec = Vec3.createVectorHelper(1, 0, 0);
vec.rotateAroundZ((float)(rand.nextDouble() * Math.PI * 2D));
vec.rotateAroundY((float)(rand.nextDouble() * Math.PI * 2D));
vec.rotateAroundX((float)(rand.nextDouble() * Math.PI * 2D));
@ -47,13 +46,14 @@ public abstract class TileEntityPileBase extends TileEntity {
prevY = y;
prevZ = z;
/*if(i == range) {
/*if(i == range || i == 1) {
NBTTagCompound data2 = new NBTTagCompound();
data2.setString("type", "vanillaExt");
data2.setString("mode", "greendust");
data2.setDouble("posX", xCoord + 0.5 + vec.xCoord * range);
data2.setDouble("posY", yCoord + 0.5 + vec.yCoord * range);
data2.setDouble("posZ", zCoord + 0.5 + vec.zCoord * range);
data2.setString("mode", i == range ? "greendust" :
i == 1 ? "reddust" : "bluedust");
data2.setDouble("posX", xCoord + 0.5 + vec.xCoord * i);
data2.setDouble("posY", yCoord + 0.5 + vec.yCoord * i);
data2.setDouble("posZ", zCoord + 0.5 + vec.zCoord * i);
MainRegistry.proxy.effectNT(data2);
}*/
@ -91,7 +91,7 @@ public abstract class TileEntityPileBase extends TileEntity {
if(entities != null)
for(EntityLivingBase e : entities) {
ContaminationUtil.contaminate(e, HazardType.RADIATION, ContaminationType.CREATIVE, flux / 2);
ContaminationUtil.contaminate(e, HazardType.RADIATION, ContaminationType.CREATIVE, flux / 4F);
}
}
}

View File

@ -2,8 +2,12 @@ package com.hbm.tileentity.machine.pile;
import com.hbm.blocks.ModBlocks;
import com.hbm.config.GeneralConfig;
import com.hbm.main.MainRegistry;
import com.hbm.packet.AuxParticlePacketNT;
import com.hbm.packet.PacketDispatcher;
import api.hbm.block.IPileNeutronReceiver;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import net.minecraft.nbt.NBTTagCompound;
public class TileEntityPileFuel extends TileEntityPileBase implements IPileNeutronReceiver {
@ -28,10 +32,21 @@ public class TileEntityPileFuel extends TileEntityPileBase implements IPileNeutr
worldObj.setBlock(xCoord, yCoord, zCoord, ModBlocks.gas_radon_dense);
}
if(worldObj.rand.nextFloat() * 2F <= this.heat / (float)this.maxHeat) {
NBTTagCompound data = new NBTTagCompound();
data.setString("type", "vanillaExt");
data.setString("mode", "smoke");
data.setDouble("mY", 0.05);
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, xCoord + 0.25 + worldObj.rand.nextDouble() * 0.5, yCoord + 1, zCoord + 0.25 + worldObj.rand.nextDouble() * 0.5),
new TargetPoint(worldObj.provider.dimensionId, xCoord + 0.5, yCoord + 1, zCoord + 0.5, 20));
MainRegistry.proxy.effectNT(data);
}
if(this.progress >= this.maxProgress) {
worldObj.setBlock(xCoord, yCoord, zCoord, ModBlocks.block_graphite_plutonium, this.getBlockMetadata() & 7, 3);
}
}
}
private void dissipateHeat() {

View File

@ -11,7 +11,7 @@ public class TileEntityPileSource extends TileEntityPileBase {
int n = this.getBlockType() == ModBlocks.block_graphite_source ? 1 : 2;
for(int i = 0; i < 12; i++) {
for(int i = 0; i < 12 * 5; i++) {
this.castRay(n, 5);
}
}