IMC recipe support for centrifuges, slightly improved centrifuge TE

or rather, slightly reduced centrifuge horribleness

2015 bobcode *shivers*
This commit is contained in:
Boblet 2021-08-23 16:47:49 +02:00
parent b8f032ffda
commit 574c46995c
8 changed files with 245 additions and 199 deletions

View File

@ -3,7 +3,9 @@ package com.hbm.blocks.fluid;
import java.util.Random;
import com.hbm.blocks.ModBlocks;
import com.hbm.blocks.generic.BlockHazard.ExtDisplayEffect;
import com.hbm.lib.RefStrings;
import com.hbm.main.MainRegistry;
import com.hbm.util.ContaminationUtil;
import com.hbm.util.ContaminationUtil.ContaminationType;
import com.hbm.util.ContaminationUtil.HazardType;
@ -15,10 +17,12 @@ import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.BlockFluidClassic;
import net.minecraftforge.fluids.Fluid;
@ -80,23 +84,17 @@ public class SchrabidicBlock extends BlockFluidClassic {
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block)
{
public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
super.onNeighborBlockChange(world, x, y, z, block);
if(reactToBlocks(world, x + 1, y, z))
world.setBlock(x, y, z, ModBlocks.sellafield_slaked);
if(reactToBlocks(world, x - 1, y, z))
world.setBlock(x, y, z, ModBlocks.sellafield_slaked);
if(reactToBlocks(world, x, y + 1, z))
world.setBlock(x, y, z, ModBlocks.sellafield_slaked);
if(reactToBlocks(world, x, y - 1, z))
world.setBlock(x, y, z, ModBlocks.sellafield_slaked);
if(reactToBlocks(world, x, y, z + 1))
world.setBlock(x, y, z, ModBlocks.sellafield_slaked);
if(reactToBlocks(world, x, y, z - 1))
world.setBlock(x, y, z, ModBlocks.sellafield_slaked);
}
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if(reactToBlocks(world, x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ)) {
world.setBlock(x, y, z, ModBlocks.sellafield_slaked);
break;
}
}
}
public boolean reactToBlocks(World world, int x, int y, int z) {
if(world.getBlock(x, y, z).getMaterial() != ModBlocks.fluidschrabidic) {
@ -111,4 +109,33 @@ public class SchrabidicBlock extends BlockFluidClassic {
public int tickRate(World p_149738_1_) {
return 15;
}
@SideOnly(Side.CLIENT)
public void randomDisplayTick(World world, int x, int y, int z, Random rand) {
super.randomDisplayTick(world, x, y, z, rand);
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if(world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ).getMaterial() == Material.air) {
double ix = x + 0.5F + dir.offsetX + rand.nextDouble() * 3 - 1.5D;
double iy = y + 0.5F + dir.offsetY + rand.nextDouble() * 3 - 1.5D;
double iz = z + 0.5F + dir.offsetZ + rand.nextDouble() * 3 - 1.5D;
if(dir.offsetX != 0)
ix = x + 0.5F + dir.offsetX * 0.5 + rand.nextDouble() * dir.offsetX;
if(dir.offsetY != 0)
iy = y + 0.5F + dir.offsetY * 0.5 + rand.nextDouble() * dir.offsetY;
if(dir.offsetZ != 0)
iz = z + 0.5F + dir.offsetZ * 0.5 + rand.nextDouble() * dir.offsetZ;
NBTTagCompound data = new NBTTagCompound();
data.setString("type", "schrabfog");
data.setDouble("posX", ix);
data.setDouble("posY", iy);
data.setDouble("posZ", iz);
MainRegistry.proxy.effectNT(data);
}
}
}
}

View File

@ -13,19 +13,19 @@ public class SchrabidicFluid extends Fluid {
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon() {
return getStillIcon();
}
public IIcon getIcon() {
return getStillIcon();
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getStillIcon() {
return SchrabidicBlock.stillIcon;
}
public IIcon getStillIcon() {
return SchrabidicBlock.stillIcon;
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getFlowingIcon() {
return SchrabidicBlock.flowingIcon;
}
public IIcon getFlowingIcon() {
return SchrabidicBlock.flowingIcon;
}
}

View File

@ -0,0 +1,49 @@
package com.hbm.handler.imc;
import java.util.HashMap;
import com.hbm.inventory.RecipesCommon;
import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class IMCCentrifuge extends IMCHandler {
public static HashMap<Object, ItemStack[]> buffer = new HashMap();
@Override
public void process(IMCMessage message) {
NBTTagCompound data = message.getNBTValue();
ItemStack[] outs = new ItemStack[4];
for(int i = 0; i < 4; i++) {
NBTTagCompound output = data.getCompoundTag("output" + (i + 1));
ItemStack out = ItemStack.loadItemStackFromNBT(output);
if(out == null) {
this.printError(message, "Output stack could not be read!");
return;
}
outs[i] = out;
}
NBTTagCompound input = data.getCompoundTag("input");
ItemStack in = ItemStack.loadItemStackFromNBT(input);
if(in != null) {
buffer.put(new RecipesCommon.ComparableStack(in), outs);
} else {
String dict = data.getString("oredict");
if(!dict.isEmpty()) {
buffer.put(dict, outs);
} else {
this.printError(message, "Input stack could not be read!");
}
}
}
}

View File

@ -22,6 +22,7 @@ public class IMCCrystallizer extends IMCHandler {
if(out == null) {
this.printError(message, "Output stack could not be read!");
return;
}
NBTTagCompound input = data.getCompoundTag("input");

View File

@ -17,7 +17,6 @@ package com.hbm.handler.imc;
[MANDATORY]
To set the input, there are two choices:
- Set another tag compound like the output called "output". This will make the input a fixed item.
- Set a string called "oredict". This will make the input an ore dict entry and allow processing of genericized items.
@ -40,4 +39,20 @@ package com.hbm.handler.imc;
new ItemStack(ModItems.ingot_steel, 1).writeToNBT(out1);
msg1.setTag("output", out1);
FMLInterModComms.sendMessage("hbm", "crystallizer", msg1);
####################### CENTRIFUGE #######################
KEY: centrifuge
VALUE: NBT
[MANDATORY]
To set the output, set four tag compound named "output1" to "output4" that hold the itemstack info (set via ItemStack.writeToNBT)
Note that the centrifuge will always output four items and does not (yet) support nulls.
[MANDATORY]
To set the input, there are two choices:
- Set another tag compound like the output called "output". This will make the input a fixed item.
- Set a string called "oredict". This will make the input an ore dict entry and allow processing of genericized items.
EXAMPLES:
Refer to the examples of the acidizer, the only difference is the fact that there are four mandatory outputs.
*/

View File

@ -6,8 +6,10 @@ import java.util.Map;
import java.util.Map.Entry;
import com.hbm.blocks.ModBlocks;
import com.hbm.handler.imc.IMCCentrifuge;
import com.hbm.inventory.RecipesCommon.ComparableStack;
import com.hbm.items.ModItems;
import com.hbm.main.MainRegistry;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
@ -248,6 +250,14 @@ public class CentrifugeRecipes {
recipes.put(new ComparableStack(ModItems.crystal_lithium), new ItemStack[] { new ItemStack(ModItems.powder_lithium, 2), new ItemStack(ModItems.powder_lithium, 2), new ItemStack(ModItems.powder_quartz, 1), new ItemStack(ModItems.fluorite, 1) });
recipes.put(new ComparableStack(ModItems.crystal_starmetal), new ItemStack[] { new ItemStack(ModItems.powder_dura_steel, 3), new ItemStack(ModItems.powder_cobalt, 3), new ItemStack(ModItems.powder_astatine, 2), new ItemStack(ModItems.nugget_mercury, 5) });
recipes.put(new ComparableStack(ModItems.crystal_cobalt), new ItemStack[] { new ItemStack(ModItems.powder_cobalt, 2), new ItemStack(ModItems.powder_iron, 3), new ItemStack(ModItems.powder_copper, 3), new ItemStack(ModItems.powder_lithium_tiny, 1) });
if(!IMCCentrifuge.buffer.isEmpty()) {
recipes.putAll(IMCCentrifuge.buffer);
MainRegistry.logger.info("Fetched " + IMCCentrifuge.buffer.size() + " IMC centrifuge recipes!");
IMCCentrifuge.buffer.clear();
}
}
public static ItemStack[] getOutput(ItemStack stack) {

View File

@ -59,6 +59,7 @@ import com.hbm.entity.particle.*;
import com.hbm.entity.projectile.*;
import com.hbm.handler.*;
import com.hbm.handler.FluidTypeHandler.FluidType;
import com.hbm.handler.imc.IMCCentrifuge;
import com.hbm.handler.imc.IMCCrystallizer;
import com.hbm.handler.imc.IMCHandler;
import com.hbm.handler.radiation.ChunkRadiationManager;
@ -1030,8 +1031,11 @@ public class MainRegistry {
// MUST be initialized AFTER achievements!!
BobmazonOfferFactory.init();
OreDictManager.registerOres();
IMCHandler.registerHandler("crystallizer", new IMCCrystallizer());
IMCHandler.registerHandler("centrifuge", new IMCCentrifuge());
IMCHandler.registerHandler("crystallizer", new IMCCrystallizer());NBTTagCompound msg0 = new NBTTagCompound();
/*NBTTagCompound msg0 = new NBTTagCompound();
NBTTagCompound ing0 = new NBTTagCompound();
new ItemStack(ModItems.alloy_plate).writeToNBT(ing0);
msg0.setTag("input", ing0);
@ -1045,7 +1049,7 @@ public class MainRegistry {
NBTTagCompound out1 = new NBTTagCompound();
new ItemStack(ModItems.ingot_steel, 1).writeToNBT(out1);
msg1.setTag("output", out1);
FMLInterModComms.sendMessage("hbm", "crystallizer", msg1);
FMLInterModComms.sendMessage("hbm", "crystallizer", msg1);*/
}
@EventHandler

View File

@ -21,22 +21,24 @@ import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
//TODO: move this trash to TileEntityMachineBase
//no seriously, this is dreadful
public class TileEntityMachineCentrifuge extends TileEntity implements ISidedInventory, IConsumer {
private ItemStack slots[];
public int dualCookTime;
public long power;
public boolean isProgressing;
public static final int maxPower = 100000;
public static final int processingSpeed = 200;
private static final int[] slots_top = new int[] {0};
private static final int[] slots_bottom = new int[] {2, 3, 4, 5};
private static final int[] slots_side = new int[] {0, 1};
private static final int[] slots_top = new int[] { 0 };
private static final int[] slots_bottom = new int[] { 2, 3, 4, 5 };
private static final int[] slots_side = new int[] { 0, 1 };
private String customName;
public TileEntityMachineCentrifuge() {
slots = new ItemStack[6];
}
@ -53,21 +55,19 @@ public class TileEntityMachineCentrifuge extends TileEntity implements ISidedInv
@Override
public ItemStack getStackInSlotOnClosing(int i) {
if(slots[i] != null)
{
if(slots[i] != null) {
ItemStack itemStack = slots[i];
slots[i] = null;
return itemStack;
} else {
return null;
return null;
}
}
@Override
public void setInventorySlotContents(int i, ItemStack itemStack) {
slots[i] = itemStack;
if(itemStack != null && itemStack.stackSize > getInventoryStackLimit())
{
if(itemStack != null && itemStack.stackSize > getInventoryStackLimit()) {
itemStack.stackSize = getInventoryStackLimit();
}
}
@ -81,7 +81,7 @@ public class TileEntityMachineCentrifuge extends TileEntity implements ISidedInv
public boolean hasCustomInventoryName() {
return this.customName != null && this.customName.length() > 0;
}
public void setCustomName(String name) {
this.customName = name;
}
@ -93,101 +93,94 @@ public class TileEntityMachineCentrifuge extends TileEntity implements ISidedInv
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
if(worldObj.getTileEntity(xCoord, yCoord, zCoord) != this)
{
if(worldObj.getTileEntity(xCoord, yCoord, zCoord) != this) {
return false;
}else{
return player.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <=64;
} else {
return player.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <= 64;
}
}
//You scrubs aren't needed for anything (right now)
// You scrubs aren't needed for anything (right now)
@Override
public void openInventory() {}
public void openInventory() {
}
@Override
public void closeInventory() {}
public void closeInventory() {
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemStack) {
if(i == 2 || i == 3 || i == 4 || i == 5)
{
if(i == 2 || i == 3 || i == 4 || i == 5) {
return false;
}
if(i == 1) {
return itemStack.getItem() instanceof IBatteryItem;
}
return !(itemStack.getItem() instanceof IBatteryItem);
}
@Override
public ItemStack decrStackSize(int i, int j) {
if(slots[i] != null)
{
if(slots[i].stackSize <= j)
{
if(slots[i] != null) {
if(slots[i].stackSize <= j) {
ItemStack itemStack = slots[i];
slots[i] = null;
return itemStack;
}
ItemStack itemStack1 = slots[i].splitStack(j);
if (slots[i].stackSize == 0)
{
if(slots[i].stackSize == 0) {
slots[i] = null;
}
return itemStack1;
} else {
return null;
}
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
NBTTagList list = nbt.getTagList("items", 10);
power = nbt.getLong("powerTime");
dualCookTime = nbt.getShort("CookTime");
slots = new ItemStack[getSizeInventory()];
for(int i = 0; i < list.tagCount(); i++)
{
for(int i = 0; i < list.tagCount(); i++) {
NBTTagCompound nbt1 = list.getCompoundTagAt(i);
byte b0 = nbt1.getByte("slot");
if(b0 >= 0 && b0 < slots.length)
{
if(b0 >= 0 && b0 < slots.length) {
slots[b0] = ItemStack.loadItemStackFromNBT(nbt1);
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
nbt.setLong("powerTime", power);
nbt.setShort("cookTime", (short) dualCookTime);
NBTTagList list = new NBTTagList();
for(int i = 0; i < slots.length; i++)
{
if(slots[i] != null)
{
for(int i = 0; i < slots.length; i++) {
if(slots[i] != null) {
NBTTagCompound nbt1 = new NBTTagCompound();
nbt1.setByte("slot", (byte)i);
nbt1.setByte("slot", (byte) i);
slots[i].writeToNBT(nbt1);
list.appendTag(nbt1);
}
}
nbt.setTag("items", list);
}
@Override
public int[] getAccessibleSlotsFromSide(int p_94128_1_)
{
return p_94128_1_ == 0 ? slots_bottom : (p_94128_1_ == 1 ? slots_top : slots_side);
}
public int[] getAccessibleSlotsFromSide(int p_94128_1_) {
return p_94128_1_ == 0 ? slots_bottom : (p_94128_1_ == 1 ? slots_top : slots_side);
}
@Override
public boolean canInsertItem(int i, ItemStack itemStack, int j) {
@ -198,176 +191,123 @@ public class TileEntityMachineCentrifuge extends TileEntity implements ISidedInv
public boolean canExtractItem(int i, ItemStack itemStack, int j) {
return j != 0 || i != 1 || itemStack.getItem() == Items.bucket;
}
public int getCentrifugeProgressScaled(int i) {
return (dualCookTime * i) / processingSpeed;
}
public long getPowerRemainingScaled(int i) {
return (power * i) / maxPower;
}
public boolean canProcess() {
if(slots[0] == null)
{
if(slots[0] == null) {
return false;
}
ItemStack[] itemStack = CentrifugeRecipes.getOutput(slots[0]);
if(itemStack == null)
{
ItemStack[] out = CentrifugeRecipes.getOutput(slots[0]);
if(out == null) {
return false;
}
if(slots[2] == null && slots[3] == null && slots[4] == null && slots[5] == null)
{
return true;
for(int i = 0; i < 4; i++) {
//either the slot is null, the output is null or the output can be added to the existing slot
if(slots[i + 2] == null)
continue;
if(out[i] == null)
continue;
if(slots[i + 2].isItemEqual(out[i]) && slots[i + 2].stackSize + out[i].stackSize <= out[i].getMaxStackSize())
continue;
return false;
}
if((slots[2] == null || (itemStack[0] != null && (slots[2].isItemEqual(itemStack[0])) && slots[2].stackSize + itemStack[0].stackSize <= itemStack[0].getMaxStackSize())) &&
(slots[3] == null || (itemStack[1] != null && (slots[3].isItemEqual(itemStack[1])) && slots[3].stackSize + itemStack[1].stackSize <= itemStack[1].getMaxStackSize())) &&
(slots[4] == null || (itemStack[2] != null && (slots[4].isItemEqual(itemStack[2])) && slots[4].stackSize + itemStack[2].stackSize <= itemStack[2].getMaxStackSize())) &&
(slots[5] == null || (itemStack[3] != null && (slots[5].isItemEqual(itemStack[3])) && slots[5].stackSize + itemStack[3].stackSize <= itemStack[3].getMaxStackSize())))
{
return true;
}
return false;
return true;
}
private void processItem() {
if(canProcess()) {
ItemStack[] itemStack = CentrifugeRecipes.getOutput(slots[0]);
if(slots[2] == null && itemStack[0] != null)
{
slots [2] = itemStack[0].copy();
}else if(itemStack[0] != null && slots[2].isItemEqual(itemStack[0]))
{
slots[2].stackSize += itemStack[0].stackSize;
}
if(slots[3] == null && itemStack[1] != null)
{
slots [3] = itemStack[1].copy();
}else if(itemStack[1] != null && slots[3].isItemEqual(itemStack[1]))
{
slots[3].stackSize += itemStack[1].stackSize;
}
if(slots[4] == null && itemStack[2] != null)
{
slots [4] = itemStack[2].copy();
}else if(itemStack[2] != null && slots[4].isItemEqual(itemStack[2]))
{
slots[4].stackSize += itemStack[2].stackSize;
}
if(slots[5] == null && itemStack[3] != null)
{
slots [5] = itemStack[3].copy();
}else if(itemStack[3] != null && slots[5].isItemEqual(itemStack[3]))
{
slots[5].stackSize += itemStack[3].stackSize;
}
for(int i = 0; i < 1; i++)
{
if(slots[i].stackSize <= 0)
{
slots[i] = new ItemStack(slots[i].getItem().setFull3D());
}else{
slots[i].stackSize--;
}
if(slots[i].stackSize <= 0)
{
slots[i] = null;
}
ItemStack[] out = CentrifugeRecipes.getOutput(slots[0]);
for(int i = 0; i < 4; i++) {
if(out[i] == null)
continue;
if(slots[i + 2] == null) {
slots[i + 2] = out[i].copy();
} else {
slots[i + 2].stackSize += out[i].stackSize;
}
}
this.decrStackSize(0, 1);
this.markDirty();
}
public boolean hasPower() {
return power > 0;
}
public boolean isProcessing() {
return this.dualCookTime > 0;
}
@Override
public void updateEntity() {
this.hasPower();
boolean flag1 = false;
if(!worldObj.isRemote) {
power = Library.chargeTEFromItems(slots, 1, power, maxPower);
if(hasPower() && isProcessing())
{
if(hasPower() && isProcessing()) {
this.power -= 200;
if(this.power < 0)
{
if(this.power < 0) {
this.power = 0;
}
}
if(hasPower() && canProcess())
{
if(hasPower() && canProcess()) {
isProgressing = true;
} else {
isProgressing = false;
}
boolean trigger = true;
if(hasPower() && canProcess() && this.dualCookTime == 0)
{
trigger = false;
}
if(trigger)
{
flag1 = true;
}
PacketDispatcher.wrapper.sendToAllAround(new AuxElectricityPacket(xCoord, yCoord, zCoord, power), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50));
PacketDispatcher.wrapper.sendToAllAround(new AuxGaugePacket(xCoord, yCoord, zCoord, dualCookTime, 0), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50));
PacketDispatcher.wrapper.sendToAllAround(new AuxGaugePacket(xCoord, yCoord, zCoord, isProgressing ? 1 : 0, 1), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50));
PacketDispatcher.wrapper.sendToAllAround(new LoopedSoundPacket(xCoord, yCoord, zCoord), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50));
PacketDispatcher.wrapper.sendToAllAround(new AuxElectricityPacket(xCoord, yCoord, zCoord, power),
new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50));
PacketDispatcher.wrapper.sendToAllAround(new AuxGaugePacket(xCoord, yCoord, zCoord, dualCookTime, 0),
new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50));
PacketDispatcher.wrapper.sendToAllAround(
new AuxGaugePacket(xCoord, yCoord, zCoord, isProgressing ? 1 : 0, 1),
new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50));
PacketDispatcher.wrapper.sendToAllAround(new LoopedSoundPacket(xCoord, yCoord, zCoord),
new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50));
}
if(hasPower() && canProcess())
{
if(hasPower() && canProcess()) {
dualCookTime++;
if(this.dualCookTime >= TileEntityMachineCentrifuge.processingSpeed)
{
if(this.dualCookTime >= TileEntityMachineCentrifuge.processingSpeed) {
this.dualCookTime = 0;
this.processItem();
}
} else {
dualCookTime = 0;
}
if(flag1)
{
this.markDirty();
}
}
@Override
public AxisAlignedBB getRenderBoundingBox() {
return TileEntity.INFINITE_EXTENT_AABB;
}
@Override
@SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared()
{
public double getMaxRenderDistanceSquared() {
return 65536.0D;
}
@ -379,7 +319,7 @@ public class TileEntityMachineCentrifuge extends TileEntity implements ISidedInv
@Override
public long getPower() {
return power;
}
@Override