Merge remote-tracking branch 'upstream/1.11' into 1.12_firstpass

This commit is contained in:
Tom Elfring committed 2017-07-26 19:38:35 +02:00
commit 69e163abd9
51 files changed
+1135 -271

No files matched your search

@@ -28,8 +28,10 @@ import net.minecraftforge.fml.common.Optional.InterfaceList;
public interface IEnergyWrapper extends IStrictEnergyStorage, IEnergyReceiver, IEnergyProvider, IEnergySink, IEnergySource, IEnergyStorage, IStrictEnergyAcceptor, IStrictEnergyOutputter, IInventory
{
public EnumSet<EnumFacing> getOutputtingSides();
public boolean sideIsOutput(EnumFacing side);
public EnumSet<EnumFacing> getConsumingSides();
public boolean sideIsConsumer(EnumFacing side);
public double getMaxOutput();
}
@@ -8,6 +8,7 @@ import mekanism.common.MekanismBlocks;
import mekanism.common.block.property.PropertyColor;
import mekanism.common.block.states.BlockStateFacing;
import mekanism.common.block.states.BlockStateGlowPanel;
import mekanism.common.integration.multipart.MultipartMekanism;
import mekanism.common.tile.TileEntityGlowPanel;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MultipartUtils;
@@ -72,7 +73,7 @@ public class BlockGlowPanel extends Block implements ITileEntityProvider
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
{
TileEntityGlowPanel tileEntity = (TileEntityGlowPanel) MekanismUtils.getTileEntitySafe(world, pos);
TileEntityGlowPanel tileEntity = getTileEntityGlowPanel(world, pos);
return tileEntity != null ? state.withProperty(BlockStateFacing.facingProperty, tileEntity.side) : state;
}
@@ -80,8 +81,8 @@ public class BlockGlowPanel extends Block implements ITileEntityProvider
@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos)
{
TileEntityGlowPanel tileEntity = (TileEntityGlowPanel) MekanismUtils.getTileEntitySafe(world, pos);
TileEntityGlowPanel tileEntity = getTileEntityGlowPanel(world, pos);
if(tileEntity != null)
{
state = state.withProperty(BlockStateFacing.facingProperty, tileEntity.side);
@@ -98,10 +99,10 @@ public class BlockGlowPanel extends Block implements ITileEntityProvider
@Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block block, BlockPos neighbor)
{
TileEntityGlowPanel tileEntity = (TileEntityGlowPanel)world.getTileEntity(pos);
TileEntityGlowPanel tileEntity = getTileEntityGlowPanel(world, pos);
if(!world.isRemote && !canStay(tileEntity))
{
if(tileEntity != null && !world.isRemote && !canStay(world, pos))
{
float motion = 0.7F;
double motionX = (rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
double motionY = (rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
@@ -118,10 +119,10 @@ public class BlockGlowPanel extends Block implements ITileEntityProvider
@Override
public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor)
{
TileEntityGlowPanel tileEntity = (TileEntityGlowPanel) MekanismUtils.getTileEntitySafe(world, pos);
TileEntityGlowPanel tileEntity = getTileEntityGlowPanel(world, pos);
if(!tileEntity.getWorld().isRemote && !canStay(tileEntity))
{
if(tileEntity != null && !tileEntity.getWorld().isRemote && !canStay(world, pos))
{
float motion = 0.7F;
double motionX = (rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
double motionY = (rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
@@ -138,11 +139,11 @@ public class BlockGlowPanel extends Block implements ITileEntityProvider
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess world, BlockPos pos)
{
TileEntity tile = MekanismUtils.getTileEntitySafe(world, pos);
TileEntityGlowPanel tileEntity = getTileEntityGlowPanel(world, pos);
if(tile != null && tile instanceof TileEntityGlowPanel)
if(tileEntity != null)
{
return bounds[((TileEntityGlowPanel)tile).side.ordinal()];
return bounds[tileEntity.side.ordinal()];
}
return super.getBoundingBox(state, world, pos);
@@ -154,10 +155,27 @@ public class BlockGlowPanel extends Block implements ITileEntityProvider
return world.isSideSolid(pos.offset(side.getOpposite()), side);
}
public static boolean canStay(TileEntityGlowPanel tileEntity)
public static boolean canStay(IBlockAccess world, BlockPos pos)
{
Coord4D adj = new Coord4D(tileEntity.getPos().offset(tileEntity.side), tileEntity.getWorld());
return tileEntity.getWorld().isSideSolid(adj.getPos(), tileEntity.side.getOpposite());
boolean canStay = false;
if(Mekanism.hooks.MCMPLoaded)
{
canStay = MultipartMekanism.hasCenterSlot(world, pos);
}
if(!canStay)
{
TileEntity tileEntity = world.getTileEntity(pos);
if(tileEntity instanceof TileEntityGlowPanel)
{
TileEntityGlowPanel glowPanel = (TileEntityGlowPanel)tileEntity;
Coord4D adj = new Coord4D(glowPanel.getPos().offset(glowPanel.side), glowPanel.getWorld());
canStay = glowPanel.getWorld().isSideSolid(adj.getPos(), glowPanel.side.getOpposite());
}
}
return canStay;
}
@Override
@@ -238,4 +256,24 @@ public class BlockGlowPanel extends Block implements ITileEntityProvider
{
return false;
}
private static TileEntityGlowPanel getTileEntityGlowPanel(IBlockAccess world, BlockPos pos)
{
TileEntity tileEntity = MekanismUtils.getTileEntitySafe(world, pos);
TileEntityGlowPanel glowPanel = null;
if(tileEntity instanceof TileEntityGlowPanel)
{
glowPanel = (TileEntityGlowPanel)tileEntity;
}
else if(Mekanism.hooks.MCMPLoaded)
{
TileEntity childEntity = MultipartMekanism.unwrapTileEntity(world);
if(childEntity instanceof TileEntityGlowPanel)
{
glowPanel = (TileEntityGlowPanel)childEntity;
}
}
return glowPanel;
}
}
@@ -14,6 +14,7 @@ import mekanism.common.block.property.PropertyConnection;
import mekanism.common.block.states.BlockStateTransmitter;
import mekanism.common.block.states.BlockStateTransmitter.TransmitterType;
import mekanism.common.block.states.BlockStateTransmitter.TransmitterType.Size;
import mekanism.common.integration.multipart.MultipartMekanism;
import mekanism.common.tile.transmitter.TileEntityDiversionTransporter;
import mekanism.common.tile.transmitter.TileEntityLogisticalTransporter;
import mekanism.common.tile.transmitter.TileEntityMechanicalPipe;
@@ -95,11 +96,10 @@ public class BlockTransmitter extends Block implements ITileEntityProvider
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
TileEntity tile = MekanismUtils.getTileEntitySafe(worldIn, pos);
if(tile instanceof TileEntitySidedPipe)
TileEntitySidedPipe tile = getTileEntitySidedPipe(worldIn, pos);
if(tile != null)
{
state = state.withProperty(BlockStateTransmitter.tierProperty, ((TileEntitySidedPipe)tile).getBaseTier());
state = state.withProperty(BlockStateTransmitter.tierProperty, tile.getBaseTier());
}
return state;
@@ -129,7 +129,7 @@ public class BlockTransmitter extends Block implements ITileEntityProvider
@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess w, BlockPos pos)
{
TileEntitySidedPipe tile = (TileEntitySidedPipe) MekanismUtils.getTileEntitySafe(w, pos);
TileEntitySidedPipe tile = getTileEntitySidedPipe(w, pos);
if(tile != null)
{
@@ -147,9 +147,9 @@ public class BlockTransmitter extends Block implements ITileEntityProvider
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess world, BlockPos pos)
{
TileEntity tile = MekanismUtils.getTileEntitySafe(world, pos);
TileEntitySidedPipe tile = getTileEntitySidedPipe(world, pos);
if(tile instanceof TileEntitySidedPipe && ((TileEntitySidedPipe)tile).getTransmitterType().getSize() == Size.SMALL)
if(tile != null && tile.getTransmitterType().getSize() == Size.SMALL)
{
return smallSides[6];
}
@@ -160,7 +160,7 @@ public class BlockTransmitter extends Block implements ITileEntityProvider
@Override
public void addCollisionBoxToList(IBlockState state, World world, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean b)
{
TileEntitySidedPipe tile = (TileEntitySidedPipe)world.getTileEntity(pos);
TileEntitySidedPipe tile = getTileEntitySidedPipe(world, pos);
if(tile != null)
{
@@ -176,13 +176,13 @@ public class BlockTransmitter extends Block implements ITileEntityProvider
@Override
public AxisAlignedBB getSelectedBoundingBox(IBlockState state, World world, BlockPos pos)
{
return getDefaultForTile((TileEntitySidedPipe)world.getTileEntity(pos)).offset(pos);
return getDefaultForTile(getTileEntitySidedPipe(world, pos)).offset(pos);
}
@Override
public RayTraceResult collisionRayTrace(IBlockState blockState, World world, BlockPos pos, Vec3d start, Vec3d end)
{
TileEntitySidedPipe tile = (TileEntitySidedPipe)world.getTileEntity(pos);
TileEntitySidedPipe tile = getTileEntitySidedPipe(world, pos);
if(tile == null)
{
@@ -226,16 +226,20 @@ public class BlockTransmitter extends Block implements ITileEntityProvider
@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player)
{
TileEntitySidedPipe tileEntity = (TileEntitySidedPipe)world.getTileEntity(pos);
ItemStack itemStack = new ItemStack(MekanismBlocks.Transmitter, 1, tileEntity.getTransmitterType().ordinal());
if(!itemStack.hasTagCompound())
ItemStack itemStack = ItemStack.EMPTY;
TileEntitySidedPipe tileEntity = getTileEntitySidedPipe(world, pos);
if(tileEntity != null)
{
itemStack.setTagCompound(new NBTTagCompound());
itemStack = new ItemStack(MekanismBlocks.Transmitter, 1, tileEntity.getTransmitterType().ordinal());
if(!itemStack.hasTagCompound())
{
itemStack.setTagCompound(new NBTTagCompound());
}
ITierItem tierItem = (ITierItem)itemStack.getItem();
tierItem.setBaseTier(itemStack, tileEntity.getBaseTier());
}
ITierItem tierItem = (ITierItem)itemStack.getItem();
tierItem.setBaseTier(itemStack, tileEntity.getBaseTier());
return itemStack;
}
@@ -285,24 +289,33 @@ public class BlockTransmitter extends Block implements ITileEntityProvider
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
TileEntitySidedPipe tile = (TileEntitySidedPipe)world.getTileEntity(pos);
tile.onAdded();
TileEntitySidedPipe tile = getTileEntitySidedPipe(world, pos);
if(tile != null)
{
tile.onAdded();
}
}
@Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block block, BlockPos neighbor)
{
TileEntitySidedPipe tile = (TileEntitySidedPipe)world.getTileEntity(pos);
EnumFacing side = EnumFacing.getFacingFromVector(neighbor.getX() - pos.getX(), neighbor.getY() - pos.getY(), neighbor.getZ() - pos.getZ());
tile.onNeighborBlockChange(side);
TileEntitySidedPipe tile = getTileEntitySidedPipe(world, pos);
if(tile != null)
{
EnumFacing side = EnumFacing.getFacingFromVector(neighbor.getX() - pos.getX(), neighbor.getY() - pos.getY(), neighbor.getZ() - pos.getZ());
tile.onNeighborBlockChange(side);
}
}
@Override
public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor)
{
TileEntitySidedPipe tile = (TileEntitySidedPipe) MekanismUtils.getTileEntitySafe(world, pos);
EnumFacing side = EnumFacing.getFacingFromVector(neighbor.getX() - pos.getX(), neighbor.getY() - pos.getY(), neighbor.getZ() - pos.getZ());
tile.onNeighborTileChange(side);
TileEntitySidedPipe tile = getTileEntitySidedPipe(world, pos);
if(tile != null)
{
EnumFacing side = EnumFacing.getFacingFromVector(neighbor.getX() - pos.getX(), neighbor.getY() - pos.getY(), neighbor.getZ() - pos.getZ());
tile.onNeighborTileChange(side);
}
}
@Override
@@ -423,4 +436,24 @@ public class BlockTransmitter extends Block implements ITileEntityProvider
return null;
}
private static TileEntitySidedPipe getTileEntitySidedPipe(IBlockAccess world, BlockPos pos)
{
TileEntity tileEntity = MekanismUtils.getTileEntitySafe(world, pos);
TileEntitySidedPipe sidedPipe = null;
if(tileEntity instanceof TileEntitySidedPipe)
{
sidedPipe = (TileEntitySidedPipe)tileEntity;
}
else if(Mekanism.hooks.MCMPLoaded)
{
TileEntity childEntity = MultipartMekanism.unwrapTileEntity(world);
if(childEntity instanceof TileEntitySidedPipe)
{
sidedPipe = (TileEntitySidedPipe)childEntity;
}
}
return sidedPipe;
}
}
@@ -446,6 +446,9 @@ public final class TransporterPathfinder
}
double maxSearchDistance = start.distanceTo(finalNode) * 2;
ArrayList<EnumFacing> directionsToCheck = new ArrayList<>();
Coord4D[] neighbors = new Coord4D[EnumFacing.VALUES.length];
TileEntity[] neighborEntities = new TileEntity[neighbors.length];
while(!openSet.isEmpty())
{
@@ -469,13 +472,34 @@ public final class TransporterPathfinder
openSet.remove(currentNode);
closedSet.add(currentNode);
TileEntity currentNodeTile = currentNode.getTileEntity(worldObj);
ILogisticalTransporter currentNodeTransporter = null;
if(currentNodeTile.hasCapability(Capabilities.LOGISTICAL_TRANSPORTER_CAPABILITY, null))
{
currentNodeTransporter =
CapabilityUtils.getCapability(currentNodeTile, Capabilities.LOGISTICAL_TRANSPORTER_CAPABILITY, null);
}
directionsToCheck.clear();
for(EnumFacing direction : EnumFacing.VALUES)
{
Coord4D neighbor = currentNode.offset(direction);
if(transportStack.canInsertToTransporter(neighbor.getTileEntity(worldObj), direction))
neighbors[direction.ordinal()] = neighbor;
TileEntity neighborEntity = neighbor.getTileEntity(worldObj);
neighborEntities[direction.ordinal()] = neighborEntity;
if(currentNodeTransporter == null || currentNodeTransporter.canEmitTo(neighborEntity, direction))
{
TileEntity tile = neighbor.getTileEntity(worldObj);
directionsToCheck.add(direction);
}
}
for(EnumFacing direction : directionsToCheck)
{
Coord4D neighbor = neighbors[direction.ordinal()];
if(transportStack.canInsertToTransporter(neighborEntities[direction.ordinal()], direction))
{
TileEntity tile = neighborEntities[direction.ordinal()];
double tentativeG = gScore.get(currentNode) + CapabilityUtils.getCapability(tile, Capabilities.LOGISTICAL_TRANSPORTER_CAPABILITY, direction.getOpposite()).getCost();
if(closedSet.contains(neighbor))
@@ -494,7 +518,7 @@ public final class TransporterPathfinder
openSet.add(neighbor);
}
}
else if(neighbor.equals(finalNode) && destChecker.isValid(transportStack, direction, neighbor.getTileEntity(worldObj)))
else if(neighbor.equals(finalNode) && destChecker.isValid(transportStack, direction, neighborEntities[direction.ordinal()]))
{
side = direction;
results = reconstructPath(navMap, currentNode);
@@ -16,6 +16,7 @@ import mekanism.common.Resource;
import mekanism.common.block.states.BlockStateTransmitter.TransmitterType;
import mekanism.common.integration.computer.CCPeripheral;
import mekanism.common.integration.computer.OCDriver;
import mekanism.common.integration.storagedrawer.StorageDrawerRecipeHandler;
import mekanism.common.recipe.RecipeHandler;
import mekanism.common.util.MekanismUtils;
import net.minecraft.init.Items;
@@ -80,6 +81,11 @@ public final class MekanismHooks
{
//loadMettallurgy();
}
if(Loader.isModLoaded("storagedrawers"))
{
StorageDrawerRecipeHandler.register();
}
}
@Method(modid = "IC2")
@@ -44,13 +44,13 @@ public class ForgeEnergyIntegration implements IEnergyStorage
@Override
public boolean canExtract()
{
return tileEntity.getOutputtingSides().contains(side);
return tileEntity.sideIsOutput(side);
}
@Override
public boolean canReceive()
{
return tileEntity.getConsumingSides().contains(side);
return tileEntity.sideIsConsumer(side);
}
public static int rfToForge(int rf)
@@ -1,11 +1,23 @@
package mekanism.common.integration.multipart;
import java.util.Random;
import mcmultipart.api.container.IPartInfo;
import mcmultipart.api.multipart.IMultipart;
import mcmultipart.api.slot.EnumFaceSlot;
import mcmultipart.api.slot.IPartSlot;
import mekanism.api.EnumColor;
import mekanism.common.MekanismBlocks;
import mekanism.common.block.BlockGlowPanel;
import mekanism.common.block.states.BlockStateFacing;
import mekanism.common.tile.TileEntityGlowPanel;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
@@ -13,6 +25,8 @@ import net.minecraft.world.World;
public class MultipartGlowPanel implements IMultipart
{
private static Random rand = new Random();
@Override
public IPartSlot getSlotForPlacement(World world, BlockPos pos, IBlockState state, EnumFacing facing, float hitX, float hitY,float hitZ, EntityLivingBase placer)
{
@@ -24,4 +38,61 @@ public class MultipartGlowPanel implements IMultipart
{
return EnumFaceSlot.values()[state.getValue(BlockStateFacing.facingProperty).ordinal()];
}
@Override
public void onPartPlacedBy(IPartInfo part, EntityLivingBase placer, ItemStack stack)
{
TileEntity tile = part.getTile().getTileEntity();
if(tile instanceof TileEntityGlowPanel)
{
EnumFacing facing = EnumFacing.values()[((EnumFaceSlot)part.getSlot()).ordinal()];
EnumColor col = EnumColor.DYES[stack.getItemDamage()];
TileEntityGlowPanel glowPanel = (TileEntityGlowPanel)tile;
glowPanel.setOrientation(facing);
glowPanel.setColour(col);
}
}
@Override
public void onPartRemoved(IPartInfo part, IPartInfo otherPart)
{
TileEntity tile = part.getTile().getTileEntity();
if(tile instanceof TileEntityGlowPanel && !BlockGlowPanel.canStay(part.getPartWorld(), part.getPartPos()))
{
float motion = 0.7F;
double motionX = (rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
double motionY = (rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
double motionZ = (rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
BlockPos pos = part.getPartPos();
TileEntityGlowPanel glowPanel = (TileEntityGlowPanel)tile;
ItemStack stack = new ItemStack(MekanismBlocks.GlowPanel, 1, glowPanel.colour.getMetaValue());
EntityItem entityItem = new EntityItem(glowPanel.getWorld(), pos.getX() + motionX, pos.getY() + motionY, pos.getZ() + motionZ, stack);
part.getActualWorld().spawnEntity(entityItem);
part.remove();
}
}
@Override
public void onPartHarvested(IPartInfo part, EntityPlayer player)
{
TileEntity tile = part.getTile().getTileEntity();
if(tile instanceof TileEntityGlowPanel)
{
IBlockState partState = part.getState();
partState.getBlock().removedByPlayer(partState, part.getPartWorld(),
part.getContainer().getPartPos(), player, true);
}
IMultipart.super.onPartHarvested(part, player);
}
@Override
public Block getBlock()
{
return MekanismBlocks.GlowPanel;
}
}
@@ -11,16 +11,21 @@ import javax.annotation.Nullable;
import mcmultipart.api.addon.IMCMPAddon;
import mcmultipart.api.addon.MCMPAddon;
import mcmultipart.api.container.IMultipartContainer;
import mcmultipart.api.container.IPartInfo;
import mcmultipart.api.multipart.IMultipart;
import mcmultipart.api.multipart.IMultipartRegistry;
import mcmultipart.api.multipart.IMultipartTile;
import mcmultipart.api.multipart.MultipartCapabilityHelper;
import mcmultipart.api.multipart.MultipartOcclusionHelper;
import mcmultipart.api.ref.MCMPCapabilities;
import mcmultipart.api.slot.EnumCenterSlot;
import mcmultipart.api.world.IMultipartBlockAccess;
import mekanism.common.MekanismBlocks;
import mekanism.common.block.BlockTransmitter;
import mekanism.common.block.states.BlockStateMachine.MachineType;
import mekanism.common.block.states.BlockStateTransmitter.TransmitterType.Size;
import mekanism.common.capabilities.Capabilities;
import mekanism.common.tile.TileEntityGlowPanel;
import mekanism.common.tile.transmitter.TileEntityTransmitter;
import net.minecraft.item.Item;
@@ -29,6 +34,8 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
@@ -63,6 +70,7 @@ public class MultipartMekanism implements IMCMPAddon
registry.registerStackWrapper(Item.getItemFromBlock(MekanismBlocks.Transmitter), s -> true, MekanismBlocks.Transmitter);
registry.registerPartWrapper(MekanismBlocks.GlowPanel, new MultipartGlowPanel());
registry.registerStackWrapper(Item.getItemFromBlock(MekanismBlocks.GlowPanel), s -> true, MekanismBlocks.GlowPanel);
MultipartCapabilityHelper.registerCapabilityJoiner(Capabilities.TILE_NETWORK_CAPABILITY, MultipartTileNetworkJoiner::new);
}
private void register(AttachCapabilitiesEvent<TileEntity> e, String id)
@@ -162,4 +170,45 @@ public class MultipartMekanism implements IMCMPAddon
return Collections.emptyList();
}
static IMultipartContainer getContainer(IBlockAccess world, BlockPos pos)
{
IMultipartContainer container = null;
if(world instanceof IMultipartBlockAccess)
{
container = ((IMultipartBlockAccess) world).getPartInfo().getContainer();
}
else
{
TileEntity possibleContainer = world.getTileEntity(pos);
if(possibleContainer instanceof IMultipartContainer)
{
container = (IMultipartContainer)possibleContainer;
}
}
return container;
}
public static boolean hasCenterSlot(IBlockAccess world, BlockPos pos)
{
boolean hasCenterSlot = false;
IMultipartContainer container = getContainer(world, pos);
if(container != null)
{
hasCenterSlot = container.getPart(EnumCenterSlot.CENTER).isPresent();
}
return hasCenterSlot;
}
public static TileEntity unwrapTileEntity(IBlockAccess world)
{
TileEntity tile = null;
if(world instanceof IMultipartBlockAccess)
{
tile = ((IMultipartBlockAccess)world).getPartInfo().getTile().getTileEntity();
}
return tile;
}
}
@@ -0,0 +1,137 @@
package mekanism.common.integration.multipart;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import io.netty.buffer.ByteBuf;
import mcmultipart.api.container.IMultipartContainer;
import mcmultipart.api.multipart.IMultipartTile;
import mcmultipart.api.slot.EnumFaceSlot;
import mcmultipart.api.slot.IPartSlot;
import mcmultipart.api.world.IMultipartBlockAccess;
import mekanism.common.base.ITileNetwork;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.IBlockAccess;
/**
* Used to route {@link ITileNetwork} packets sent to multipart containers with more than one possible recipient.<br>
* <br>
* When MCMP is enabled single byte EnumFacing ordinal headers are added to packets sent by glow panels and
* transmitters that are then used by this class to route packets to the part attached to the appropriate side.<br>
* <br>
* In this case, since transmitters do not attach to a side and therefore have no matching EnumFacing the special
* value 6 is used to represent the center slot.
*/
public class MultipartTileNetworkJoiner implements ITileNetwork
{
private final HashMap<Byte, ITileNetwork> tileSideMap;
/**
* Called by MCMP's multipart container when more than one part implements {@link ITileNetwork}.<br>
* <br>
* Builds an internal map of part slots to {@link ITileNetwork} implementations in order to route packets.
* @param tileList A list of the tile entities that implement {@link ITileNetwork} in the container.
*/
public MultipartTileNetworkJoiner(List<ITileNetwork> tileList)
{
tileSideMap = new HashMap<>();
IMultipartContainer container = null;
TileEntity first = (TileEntity)tileList.get(0);
IBlockAccess world = first.getWorld();
if(world instanceof IMultipartBlockAccess)
{
container = ((IMultipartBlockAccess)world).getPartInfo().getContainer();
}
else
{
TileEntity worldTile = first.getWorld().getTileEntity(first.getPos());
if(worldTile instanceof IMultipartContainer)
{
container = (IMultipartContainer)worldTile;
}
}
if(container != null)
{
for(IPartSlot slot : container.getParts().keySet())
{
int tileIndex = tileList.indexOf(container.getPartTile(slot).get().getTileEntity());
if(tileIndex >= 0)
{
byte slotValue = slot instanceof EnumFaceSlot ? (byte)((EnumFaceSlot)slot).ordinal() : 6;
tileSideMap.put(slotValue, tileList.get(tileIndex));
}
}
}
}
@Override
public void handlePacketData(ByteBuf dataStream) throws Exception
{
while(dataStream.readableBytes() > 0)
{
byte side = dataStream.readByte();
ITileNetwork networkTile = tileSideMap.get(side);
if(networkTile == null)
{
break;
}
networkTile.handlePacketData(dataStream);
}
}
@Override
public ArrayList<Object> getNetworkedData(ArrayList<Object> data)
{
ArrayList<Object> childData = new ArrayList<>();
for(byte slotValue : tileSideMap.keySet())
{
tileSideMap.get(slotValue).getNetworkedData(childData);
data.addAll(childData);
childData.clear();
}
return data;
}
/**
* Determines whether or not an {@link ITileNetwork} joiner is needed and, if so, adds a single byte header
* used to route packets inside multipart containers.
* @param entity The entity for which <code>getNetworkedData</code> is being called
* @param data The network data list
* @param facing The side this part is attached to or <code>null</code> for the center slot
*/
public static void addMultipartHeader(TileEntity entity, ArrayList<Object> data, EnumFacing facing)
{
int tileNetworkParts = 0;
IMultipartContainer container = MultipartMekanism.getContainer(entity.getWorld(), entity.getPos());
if(container != null)
{
for(IPartSlot slot : container.getParts().keySet())
{
TileEntity part = container.getPartTile(slot)
.map(multiPartTile -> multiPartTile.getTileEntity())
.orElse(null);
if(part instanceof ITileNetwork)
{
tileNetworkParts++;
if(tileNetworkParts > 1)
{
break;
}
}
}
}
if(tileNetworkParts > 1)
{
data.add(0, (byte)(facing == null ? 6 : facing.ordinal()));
}
}
}
@@ -4,9 +4,14 @@ import mcmultipart.api.container.IPartInfo;
import mcmultipart.api.multipart.IMultipart;
import mcmultipart.api.slot.EnumCenterSlot;
import mcmultipart.api.slot.IPartSlot;
import mekanism.common.MekanismBlocks;
import mekanism.common.Tier.BaseTier;
import mekanism.common.tile.transmitter.TileEntitySidedPipe;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
@@ -27,6 +32,29 @@ public class MultipartTransmitter implements IMultipart
return EnumCenterSlot.CENTER;
}
@Override
public void onAdded(IPartInfo part)
{
TileEntity tile = part.getTile().getTileEntity();
if(tile instanceof TileEntitySidedPipe)
{
((TileEntitySidedPipe)tile).onAdded();
}
}
@Override
public void onPartAdded(IPartInfo part, IPartInfo otherPart)
{
TileEntity tile = part.getTile().getTileEntity();
if(tile instanceof TileEntitySidedPipe)
{
tile.validate();
((TileEntitySidedPipe)tile).notifyTileChange();
}
}
@Override
public void onPartChanged(IPartInfo part, IPartInfo otherPart)
{
@@ -37,4 +65,42 @@ public class MultipartTransmitter implements IMultipart
((TileEntitySidedPipe)tile).onPartChanged(otherPart.getPart());
}
}
@Override
public void onPartHarvested(IPartInfo part, EntityPlayer player)
{
TileEntity tile = part.getTile().getTileEntity();
if(tile instanceof TileEntitySidedPipe)
{
IBlockState partState = part.getState();
partState.getBlock().removedByPlayer(partState, part.getPartWorld(),
part.getContainer().getPartPos(), player, true);
}
IMultipart.super.onPartHarvested(part, player);
}
@Override
public void onPartPlacedBy(IPartInfo part, EntityLivingBase placer, ItemStack stack)
{
TileEntity tile = part.getTile().getTileEntity();
if(tile instanceof TileEntitySidedPipe)
{
BaseTier baseTier = BaseTier.BASIC;
if(stack.hasTagCompound())
{
baseTier = BaseTier.values()[stack.getTagCompound().getInteger("tier")];
}
((TileEntitySidedPipe)tile).setBaseTier(baseTier);
}
}
@Override
public Block getBlock()
{
return MekanismBlocks.Transmitter;
}
}
@@ -0,0 +1,55 @@
package mekanism.common.integration.storagedrawer;
import com.jaquadro.minecraft.storagedrawers.api.IStorageDrawersApi;
import com.jaquadro.minecraft.storagedrawers.api.StorageDrawersApi;
import com.jaquadro.minecraft.storagedrawers.api.registry.IRecipeHandler;
import com.jaquadro.minecraft.storagedrawers.api.registry.IRecipeHandlerRegistry;
import mekanism.common.recipe.ShapedMekanismRecipe;
import mekanism.common.recipe.ShapelessMekanismRecipe;
import net.minecraft.item.crafting.IRecipe;
import java.util.List;
public class StorageDrawerRecipeHandler
{
private StorageDrawerRecipeHandler(){}
public static void register()
{
IStorageDrawersApi api = StorageDrawersApi.instance();
if(api == null)
{
return;
}
IRecipeHandlerRegistry recipeHandlerRegistry = api.recipeHandlerRegistry();
recipeHandlerRegistry.registerRecipeHandler(ShapedMekanismRecipe.class, new ShapedMekanismRecipeHandler());
recipeHandlerRegistry.registerRecipeHandler(ShapelessMekanismRecipe.class, new ShapelessMekanismRecipeHandler());
}
private static class ShapedMekanismRecipeHandler implements IRecipeHandler
{
@Override
public Object[] getInputAsArray (IRecipe recipe) {
return ((ShapedMekanismRecipe) recipe).getInput();
}
@Override
public List getInputAsList (IRecipe recipe) {
return null;
}
}
private static class ShapelessMekanismRecipeHandler implements IRecipeHandler
{
@Override
public Object[] getInputAsArray (IRecipe recipe) {
return null;
}
@Override
public List getInputAsList (IRecipe recipe) {
return ((ShapelessMekanismRecipe) recipe).getInput();
}
}
}
@@ -60,7 +60,7 @@ public class PacketConfigurationUpdate implements IMessageHandler<ConfigurationU
}
else if(message.clickType == 2)
{
((ISideConfiguration)tile).getConfig().getConfig(message.transmission)[message.configIndex.ordinal()] = 0;
((ISideConfiguration)tile).getConfig().getConfig(message.transmission).set(message.configIndex, (byte) 0);
}
tile.markDirty();
@@ -34,89 +34,97 @@ public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock imp
@Override
public boolean isEmpty()
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return true;
}
return getInv().isEmpty();
return inv.isEmpty();
}
@Override
public int getSizeInventory()
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return 0;
}
return getInv().getSizeInventory();
return inv.getSizeInventory();
}
@Override
public ItemStack getStackInSlot(int i)
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return ItemStack.EMPTY;
}
return getInv().getStackInSlot(i);
return inv.getStackInSlot(i);
}
@Override
public ItemStack decrStackSize(int i, int j)
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return ItemStack.EMPTY;
}
return getInv().decrStackSize(i, j);
return inv.decrStackSize(i, j);
}
@Override
public ItemStack removeStackFromSlot(int i)
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return ItemStack.EMPTY;
}
return getInv().removeStackFromSlot(i);
return inv.removeStackFromSlot(i);
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack)
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return;
}
getInv().setInventorySlotContents(i, itemstack);
inv.setInventorySlotContents(i, itemstack);
}
@Override
public String getName()
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return "null";
}
return getInv().getName();
return inv.getName();
}
@Override
public boolean hasCustomName()
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return false;
}
return getInv().hasCustomName();
return inv.hasCustomName();
}
@Override
@@ -128,56 +136,61 @@ public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock imp
@Override
public int getInventoryStackLimit()
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return 0;
}
return getInv().getInventoryStackLimit();
return inv.getInventoryStackLimit();
}
@Override
public boolean isUsableByPlayer(EntityPlayer entityplayer)
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return false;
}
return getInv().isUsableByPlayer(entityplayer);
return inv.isUsableByPlayer(entityplayer);
}
@Override
public void openInventory(EntityPlayer player)
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return;
}
getInv().openInventory(player);
inv.openInventory(player);
}
@Override
public void closeInventory(EntityPlayer player)
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return;
}
getInv().closeInventory(player);
inv.closeInventory(player);
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return false;
}
return getInv().canBoundInsert(getPos(), i, itemstack);
return inv.canBoundInsert(getPos(), i, itemstack);
}
@Override
@@ -204,12 +217,13 @@ public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock imp
@Override
public int[] getSlotsForFace(EnumFacing side)
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return InventoryUtils.EMPTY;
}
return getInv().getBoundSlots(getPos(), side);
return inv.getBoundSlots(getPos(), side);
}
@Override
@@ -221,59 +235,58 @@ public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock imp
@Override
public boolean canExtractItem(int i, ItemStack itemstack, EnumFacing side)
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return false;
}
return getInv().canBoundExtract(getPos(), i, itemstack, side);
return inv.canBoundExtract(getPos(), i, itemstack, side);
}
@Override
@Method(modid = "IC2")
public boolean acceptsEnergyFrom(IEnergyEmitter emitter, EnumFacing direction)
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return false;
}
return getInv().acceptsEnergyFrom(emitter, direction);
return inv.acceptsEnergyFrom(emitter, direction);
}
@Override
@Method(modid = "redstoneflux")
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate)
{
if(getInv() == null || !canReceiveEnergy(from))
IAdvancedBoundingBlock inv = getInv();
if(inv == null || !canReceiveEnergy(from))
{
return 0;
}
return getInv().receiveEnergy(from, maxReceive, simulate);
return inv.receiveEnergy(from, maxReceive, simulate);
}
@Override
@Method(modid = "redstoneflux")
public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate)
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return 0;
}
return getInv().extractEnergy(from, maxExtract, simulate);
return inv.extractEnergy(from, maxExtract, simulate);
}
@Override
@Method(modid = "redstoneflux")
public boolean canConnectEnergy(EnumFacing from)
{
if(getInv() == null)
{
return false;
}
return canReceiveEnergy(from);
}
@@ -281,82 +294,84 @@ public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock imp
@Method(modid = "redstoneflux")
public int getEnergyStored(EnumFacing from)
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return 0;
}
return getInv().getEnergyStored(from);
return inv.getEnergyStored(from);
}
@Override
@Method(modid = "redstoneflux")
public int getMaxEnergyStored(EnumFacing from)
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return 0;
}
return getInv().getMaxEnergyStored(from);
return inv.getMaxEnergyStored(from);
}
@Override
public double acceptEnergy(EnumFacing side, double amount, boolean simulate)
{
if(getInv() == null || !canReceiveEnergy(side))
IAdvancedBoundingBlock inv = getInv();
if(inv == null || !canReceiveEnergy(side))
{
return 0;
}
return getInv().acceptEnergy(side, amount, simulate);
return inv.acceptEnergy(side, amount, simulate);
}
@Override
public boolean canReceiveEnergy(EnumFacing side)
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return false;
}
return getInv().canBoundReceiveEnergy(getPos(), side);
return inv.canBoundReceiveEnergy(getPos(), side);
}
@Override
@Method(modid = "IC2")
public double getDemandedEnergy()
{
if(getInv() == null)
{
return 0;
}
return getInv().getDemandedEnergy();
IAdvancedBoundingBlock inv = getInv();
return inv == null ? 0 : inv.getDemandedEnergy();
}
@Override
@Method(modid = "IC2")
public double injectEnergy(EnumFacing directionFrom, double amount, double voltage)
{
if(getInv() == null || !canReceiveEnergy(directionFrom))
IAdvancedBoundingBlock inv = getInv();
if(inv == null || !canReceiveEnergy(directionFrom))
{
return amount;
}
return getInv().injectEnergy(directionFrom, amount, voltage);
return inv.injectEnergy(directionFrom, amount, voltage);
}
@Override
@Method(modid = "IC2")
public int getSinkTier()
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return 0;
}
return getInv().getSinkTier();
return inv.getSinkTier();
}
public IAdvancedBoundingBlock getInv()
@@ -374,7 +389,7 @@ public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock imp
return null;
}
return (IAdvancedBoundingBlock)new Coord4D(mainPos, world).getTileEntity(world);
return (IAdvancedBoundingBlock) tile;
}
@Override
@@ -382,9 +397,10 @@ public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock imp
{
super.onPower();
if(getInv() != null)
IAdvancedBoundingBlock inv = getInv();
if(inv != null)
{
getInv().onPower();
inv.onPower();
}
}
@@ -393,86 +409,104 @@ public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock imp
{
super.onNoPower();
if(getInv() != null)
IAdvancedBoundingBlock inv = getInv();
if(inv != null)
{
getInv().onNoPower();
inv.onNoPower();
}
}
@Override
public String[] getMethods()
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return new String[] {};
}
return getInv().getMethods();
return inv.getMethods();
}
@Override
public Object[] invoke(int method, Object[] arguments) throws Exception
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return new Object[] {};
}
return getInv().invoke(method, arguments);
return inv.invoke(method, arguments);
}
@Override
public NBTTagCompound getConfigurationData(NBTTagCompound nbtTags)
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return new NBTTagCompound();
}
return getInv().getConfigurationData(nbtTags);
return inv.getConfigurationData(nbtTags);
}
@Override
public void setConfigurationData(NBTTagCompound nbtTags)
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return;
}
getInv().setConfigurationData(nbtTags);
inv.setConfigurationData(nbtTags);
}
@Override
public String getDataType()
{
if(getInv() == null)
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return "null";
}
return getInv().getDataType();
return inv.getDataType();
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing)
{
if(getInv() == null || capability == Capabilities.TILE_NETWORK_CAPABILITY)
if (capability == Capabilities.TILE_NETWORK_CAPABILITY)
{
return super.hasCapability(capability, facing);
}
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return super.hasCapability(capability, facing);
}
return getInv().hasCapability(capability, facing);
return inv.hasCapability(capability, facing);
}
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
{
if(getInv() == null || capability == Capabilities.TILE_NETWORK_CAPABILITY)
if (capability == Capabilities.TILE_NETWORK_CAPABILITY)
{
return super.getCapability(capability, facing);
}
IAdvancedBoundingBlock inv = getInv();
if(inv == null)
{
return super.getCapability(capability, facing);
}
return getInv().getCapability(capability, facing);
return inv.getCapability(capability, facing);
}
}
@@ -175,6 +175,11 @@ public class TileEntityChargepad extends TileEntityNoisyBlock
return EnumSet.of(EnumFacing.DOWN, facing.getOpposite());
}
@Override
public boolean sideIsConsumer(EnumFacing side) {
return side == EnumFacing.DOWN || side == facing.getOpposite();
}
@Override
public boolean getActive()
{
@@ -1565,6 +1565,13 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
return EnumSet.of(MekanismUtils.getLeft(facing), MekanismUtils.getRight(facing), EnumFacing.DOWN);
}
@Override
public boolean sideIsConsumer(EnumFacing side)
{
return side == MekanismUtils.getLeft(facing) || side == MekanismUtils.getRight(facing) || side == EnumFacing.DOWN;
}
@Override
public TileComponentSecurity getSecurity()
{
@@ -421,6 +421,12 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
return EnumSet.of(facing.getOpposite());
}
@Override
public boolean sideIsConsumer(EnumFacing side)
{
return facing.getOpposite() == side;
}
@Override
public boolean canSetFacing(int side)
{
@@ -161,12 +161,24 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements ICo
return configComponent.getSidesForData(TransmissionType.ENERGY, facing, 1);
}
@Override
public boolean sideIsConsumer(EnumFacing side)
{
return configComponent.hasSideForData(TransmissionType.ENERGY, facing, 1, side);
}
@Override
public EnumSet<EnumFacing> getOutputtingSides()
{
return configComponent.getSidesForData(TransmissionType.ENERGY, facing, 2);
}
@Override
public boolean sideIsOutput(EnumFacing side)
{
return configComponent.hasSideForData(TransmissionType.ENERGY, facing, 2, side);
}
@Override
public boolean canSetFacing(int side)
{
@@ -394,6 +394,12 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt
{
return configComponent.getSidesForData(TransmissionType.ENERGY, facing, 1);
}
@Override
public boolean sideIsConsumer(EnumFacing side)
{
return configComponent.hasSideForData(TransmissionType.ENERGY, facing, 1, side);
}
public void sortInventory()
{
@@ -245,10 +245,10 @@ public class TileEntityFluidTank extends TileEntityContainerBlock implements IAc
public int pushUp(FluidStack fluid, boolean doFill)
{
Coord4D up = Coord4D.get(this).offset(EnumFacing.UP);
if(up.getTileEntity(world) instanceof TileEntityFluidTank)
TileEntity tileEntity = up.getTileEntity(world);
if(tileEntity instanceof TileEntityFluidTank)
{
IFluidHandler handler = CapabilityUtils.getCapability(up.getTileEntity(world), CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.DOWN);
IFluidHandler handler = CapabilityUtils.getCapability(tileEntity, CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.DOWN);
if(PipeUtils.canFill(handler, fluid))
{
@@ -565,7 +565,7 @@ public class TileEntityFluidTank extends TileEntityContainerBlock implements IAc
public boolean canFill(EnumFacing from, Fluid fluid)
{
TileEntity tile = world.getTileEntity(getPos().offset(EnumFacing.DOWN));
if(from == EnumFacing.DOWN && world != null && getPos() != null)
if(from == EnumFacing.DOWN && world != null)
{
if(isActive && !(tile instanceof TileEntityFluidTank))
{
@@ -384,6 +384,12 @@ public class TileEntityFluidicPlenisher extends TileEntityElectricBlock implemen
return EnumSet.of(facing.getOpposite());
}
@Override
public boolean sideIsConsumer(EnumFacing side)
{
return facing.getOpposite() == side;
}
@Override
public boolean canSetFacing(int side)
{
@@ -244,7 +244,7 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH
@Override
public boolean canReceiveGas(EnumFacing side, Gas type)
{
if(configComponent.getSidesForData(TransmissionType.GAS, facing, 1).contains(side))
if(configComponent.hasSideForData(TransmissionType.GAS, facing, 1, side))
{
return gasTank.canReceive(type);
}
@@ -11,6 +11,7 @@ import mekanism.common.base.ITileNetwork;
import mekanism.common.block.property.PropertyColor;
import mekanism.common.block.states.BlockStateFacing;
import mekanism.common.capabilities.Capabilities;
import mekanism.common.integration.multipart.MultipartTileNetworkJoiner;
import mekanism.common.network.PacketDataRequest.DataRequestMessage;
import mekanism.common.util.MekanismUtils;
import net.minecraft.nbt.NBTTagCompound;
@@ -46,6 +47,11 @@ public class TileEntityGlowPanel extends TileEntity implements ITileNetwork
@Override
public ArrayList<Object> getNetworkedData(ArrayList<Object> data)
{
if(Mekanism.hooks.MCMPLoaded)
{
MultipartTileNetworkJoiner.addMultipartHeader(this, data, side);
}
data.add(side.ordinal());
data.add(colour.getMetaValue());
@@ -73,6 +79,12 @@ public class TileEntityGlowPanel extends TileEntity implements ITileNetwork
return nbt;
}
@Override
public NBTTagCompound getUpdateTag()
{
return writeToNBT(new NBTTagCompound());
}
@Override
public void readFromNBT(NBTTagCompound nbt)
@@ -102,6 +102,15 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement
return EnumSet.noneOf(EnumFacing.class);
}
@Override
public boolean sideIsOutput(EnumFacing side) {
if (structure != null && mode)
{
return !structure.locations.contains(Coord4D.get(this).offset(side));
}
return false;
}
@Override
public EnumSet<EnumFacing> getConsumingSides()
{
@@ -112,7 +121,12 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement
return EnumSet.noneOf(EnumFacing.class);
}
@Override
public boolean sideIsConsumer(EnumFacing side) {
return (structure != null && !mode);
}
@Method(modid = "IC2")
public void register()
{
@@ -242,7 +256,7 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement
@Method(modid = "redstoneflux")
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate)
{
if(getConsumingSides().contains(from))
if(sideIsConsumer(from))
{
double toAdd = (int)Math.min(Math.min(getMaxInput(), getMaxEnergy()-getEnergy()), maxReceive* general.FROM_RF);
@@ -262,7 +276,7 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement
@Method(modid = "redstoneflux")
public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate)
{
if(getOutputtingSides().contains(from))
if(sideIsOutput(from))
{
double toSend = Math.min(getEnergy(), Math.min(getMaxOutput(), maxExtract*general.FROM_RF));
@@ -340,21 +354,21 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement
@Override
public boolean canOutputEnergy(EnumFacing side)
{
return getOutputtingSides().contains(side);
return sideIsOutput(side);
}
@Override
@Method(modid = "IC2")
public boolean acceptsEnergyFrom(IEnergyEmitter emitter, EnumFacing direction)
{
return getConsumingSides().contains(direction);
return sideIsConsumer(direction);
}
@Override
@Method(modid = "IC2")
public boolean emitsEnergyTo(IEnergyAcceptor receiver, EnumFacing direction)
{
return getOutputtingSides().contains(direction) && receiver instanceof IEnergyConductor;
return sideIsOutput(direction) && receiver instanceof IEnergyConductor;
}
@Override
@@ -395,7 +409,7 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement
@Override
public boolean canReceiveEnergy(EnumFacing side)
{
return getConsumingSides().contains(side);
return sideIsConsumer(side);
}
@Override
@@ -433,13 +447,13 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement
@Override
public double acceptEnergy(EnumFacing side, double amount, boolean simulate)
{
if(!getConsumingSides().contains(side))
double toUse = Math.min(Math.min(getMaxInput(), getMaxEnergy()-getEnergy()), amount);
if(toUse < 0.0001 || (side != null && !sideIsConsumer(side)))
{
return 0;
}
double toUse = Math.min(Math.min(getMaxInput(), getMaxEnergy()-getEnergy()), amount);
if(!simulate)
{
setEnergy(getEnergy() + toUse);
@@ -452,14 +466,18 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement
@Override
public double pullEnergy(EnumFacing side, double amount, boolean simulate)
{
if(!getOutputtingSides().contains(side))
double toGive = Math.min(getEnergy(), amount);
if(toGive < 0.0001 || (side != null && !sideIsOutput(side)))
{
return 0;
}
double toGive = Math.min(getEnergy(), amount);
setEnergy(getEnergy() - toGive);
if (!simulate)
{
setEnergy(getEnergy() - toGive);
}
return toGive;
}
@@ -517,8 +535,8 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement
|| capability == Capabilities.ENERGY_OUTPUTTER_CAPABILITY
|| capability == Capabilities.TESLA_HOLDER_CAPABILITY
|| capability == Capabilities.CONFIGURABLE_CAPABILITY
|| (capability == Capabilities.TESLA_CONSUMER_CAPABILITY && getConsumingSides().contains(facing))
|| (capability == Capabilities.TESLA_PRODUCER_CAPABILITY && getOutputtingSides().contains(facing))
|| (capability == Capabilities.TESLA_CONSUMER_CAPABILITY && sideIsConsumer(facing))
|| (capability == Capabilities.TESLA_PRODUCER_CAPABILITY && sideIsOutput(facing))
|| capability == CapabilityEnergy.ENERGY
|| super.hasCapability(capability, facing);
}
@@ -536,8 +554,8 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement
}
if(capability == Capabilities.TESLA_HOLDER_CAPABILITY
|| (capability == Capabilities.TESLA_CONSUMER_CAPABILITY && getConsumingSides().contains(facing))
|| (capability == Capabilities.TESLA_PRODUCER_CAPABILITY && getOutputtingSides().contains(facing)))
|| (capability == Capabilities.TESLA_CONSUMER_CAPABILITY && sideIsConsumer(facing))
|| (capability == Capabilities.TESLA_PRODUCER_CAPABILITY && sideIsOutput(facing)))
{
return (T)teslaManager.getWrapper(this, facing);
}
@@ -123,7 +123,12 @@ public class TileEntityLaser extends TileEntityNoisyBlock implements IActiveStat
{
return EnumSet.of(facing.getOpposite());
}
@Override
public boolean sideIsConsumer(EnumFacing side) {
return side == facing.getOpposite();
}
@Override
public void setActive(boolean active)
{
@@ -196,6 +196,11 @@ public class TileEntityLaserAmplifier extends TileEntityContainerBlock implement
public double pullEnergy(EnumFacing side, double amount, boolean simulate)
{
double toGive = Math.min(getEnergy(), amount);
if (toGive < 0.0001)
{
return 0;
}
if(!simulate)
{
@@ -558,6 +558,11 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen
return EnumSet.noneOf(EnumFacing.class);
}
@Override
public boolean sideIsConsumer(EnumFacing side) {
return false;
}
@Override
public boolean canSetFacing(int facing)
{
@@ -184,7 +184,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityOperationalMachine i
for(TransmissionType transmission : configComponent.transmissions)
{
factory.configComponent.setConfig(transmission, configComponent.getConfig(transmission));
factory.configComponent.setConfig(transmission, configComponent.getConfig(transmission).asByteArray());
factory.configComponent.setEjecting(transmission, configComponent.isEjecting(transmission));
}
@@ -372,12 +372,30 @@ public class TileEntityQuantumEntangloporter extends TileEntityElectricBlock imp
return !hasFrequency() ? nothing : configComponent.getSidesForData(TransmissionType.ENERGY, facing, 2);
}
@Override
public boolean sideIsOutput(EnumFacing side) {
if (!hasFrequency())
{
return false;
}
return configComponent.hasSideForData(TransmissionType.ENERGY, facing, 2, side);
}
@Override
public EnumSet<EnumFacing> getConsumingSides()
{
return !hasFrequency() ? nothing : configComponent.getSidesForData(TransmissionType.ENERGY, facing, 1);
}
@Override
public boolean sideIsConsumer(EnumFacing side) {
if (!hasFrequency())
{
return false;
}
return configComponent.hasSideForData(TransmissionType.ENERGY, facing, 1, side);
}
@Override
public double getMaxOutput()
{
@@ -129,7 +129,12 @@ public class TileEntityResistiveHeater extends TileEntityNoisyBlock implements I
{
return EnumSet.of(MekanismUtils.getLeft(facing), MekanismUtils.getRight(facing));
}
@Override
public boolean sideIsConsumer(EnumFacing side) {
return side == MekanismUtils.getLeft(facing) || side == MekanismUtils.getRight(facing);
}
@Override
public boolean canSetFacing(int side)
{
@@ -213,6 +213,11 @@ public class TileEntitySeismicVibrator extends TileEntityElectricBlock implement
return EnumSet.of(facing.getOpposite());
}
@Override
public boolean sideIsConsumer(EnumFacing side) {
return side == facing.getOpposite();
}
@Override
public void setControlType(RedstoneControl type)
{
@@ -0,0 +1,63 @@
package mekanism.common.tile.component;
import net.minecraft.util.EnumFacing;
import java.util.Observable;
import java.util.Observer;
public class SideConfig
{
private byte[] directions = new byte[EnumFacing.VALUES.length];
private Observable observable = new Observable();
public SideConfig() {}
public SideConfig(byte[] b)
{
this(b[0], b[1], b[2], b[3], b[4], b[5]);
assert b.length == EnumFacing.VALUES.length;
}
public SideConfig(byte d, byte u, byte n, byte s, byte w, byte e)
{
setDirections(d, u, n, s, w, e);
}
public void setDirections(byte d, byte u, byte n, byte s, byte w, byte e)
{
directions[0] = d;
directions[1] = u;
directions[2] = n;
directions[3] = s;
directions[4] = w;
directions[5] = e;
observable.notifyObservers(this);
}
public byte get(EnumFacing f)
{
return directions[f.ordinal()];
}
public byte[] asByteArray()
{
return directions;
}
public void set(EnumFacing f, byte value)
{
directions[f.ordinal()] = value;
observable.notifyObservers(this);
}
public void addObserver(Observer o)
{
observable.addObserver(o);
}
public void deleteObserver(Observer o)
{
observable.deleteObserver(o);
}
}
@@ -25,12 +25,12 @@ public class TileComponentConfig implements ITileComponent
public TileEntityContainerBlock tileEntity;
public Map<Integer, byte[]> sideConfigs = new HashMap<Integer, byte[]>();
public Map<Integer, ArrayList<SideData>> sideOutputs = new HashMap<Integer, ArrayList<SideData>>();
public Map<Integer, Boolean> ejecting = new HashMap<Integer, Boolean>();
public Map<Integer, Boolean> canEject = new HashMap<Integer, Boolean>();
private Map<TransmissionType, SideConfig> sideConfigs = new HashMap<>();
private Map<TransmissionType, ArrayList<SideData>> sideOutputs = new HashMap<>();
private Map<TransmissionType, Boolean> ejecting = new HashMap<>();
private Map<TransmissionType, Boolean> canEject = new HashMap<>();
public List<TransmissionType> transmissions = new ArrayList<TransmissionType>();
public List<TransmissionType> transmissions = new ArrayList<>();
public TileComponentConfig(TileEntityContainerBlock tile, TransmissionType... types)
{
@@ -59,43 +59,53 @@ public class TileComponentConfig implements ITileComponent
transmissions.add(type);
}
sideOutputs.put(type.ordinal(), new ArrayList<SideData>());
ejecting.put(type.ordinal(), false);
canEject.put(type.ordinal(), true);
sideOutputs.put(type, new ArrayList<>());
ejecting.put(type, false);
canEject.put(type, true);
}
public EnumSet<EnumFacing> getSidesForData(TransmissionType type, EnumFacing facing, int dataIndex)
{
EnumSet<EnumFacing> ret = EnumSet.noneOf(EnumFacing.class);
SideConfig config = getConfig(type);
EnumFacing[] translatedFacings = MekanismUtils.getBaseOrientations(facing);
for(EnumFacing f : EnumFacing.VALUES)
for(EnumFacing sideToCheck : EnumFacing.values())
{
EnumFacing side = MekanismUtils.getBaseOrientation(f, facing);
if(getConfig(type)[side.ordinal()] == dataIndex)
if(config.get(translatedFacings[sideToCheck.ordinal()]) == dataIndex)
{
ret.add(f);
ret.add(sideToCheck);
}
}
return ret;
}
public boolean hasSideForData(TransmissionType type, EnumFacing facing, int dataIndex, EnumFacing sideToTest)
{
if(sideToTest == null)
{
return false;
}
EnumFacing[] translatedFacings = MekanismUtils.getBaseOrientations(facing);
return getConfig(type).get(translatedFacings[sideToTest.ordinal()]) == dataIndex;
}
public void setCanEject(TransmissionType type, boolean eject)
{
canEject.put(type.ordinal(), eject);
canEject.put(type, eject);
}
public boolean canEject(TransmissionType type)
{
return canEject.get(type.ordinal());
return canEject.get(type);
}
public void fillConfig(TransmissionType type, int data)
{
byte sideData = (byte)data;
setConfig(type, new byte[] {sideData, sideData, sideData, sideData, sideData, sideData});
setConfig(type, sideData, sideData, sideData, sideData, sideData, sideData);
}
public void setIOConfig(TransmissionType type)
@@ -115,25 +125,31 @@ public class TileComponentConfig implements ITileComponent
fillConfig(type, 1);
setCanEject(type, false);
}
public void setConfig(TransmissionType type, byte[] config)
{
sideConfigs.put(type.ordinal(), config);
assert config.length == EnumFacing.VALUES.length;
setConfig(type, config[0], config[1], config[2], config[3], config[4], config[5]);
}
public void setConfig(TransmissionType type, byte d, byte u, byte n, byte s, byte w, byte e)
{
sideConfigs.put(type, new SideConfig(d, u, n, s, w, e));
}
public void addOutput(TransmissionType type, SideData data)
{
sideOutputs.get(type.ordinal()).add(data);
sideOutputs.get(type).add(data);
}
public ArrayList<SideData> getOutputs(TransmissionType type)
{
return sideOutputs.get(type.ordinal());
return sideOutputs.get(type);
}
public byte[] getConfig(TransmissionType type)
public SideConfig getConfig(TransmissionType type)
{
return sideConfigs.get(type.ordinal());
return sideConfigs.get(type);
}
public SideData getOutput(TransmissionType type, EnumFacing side, EnumFacing facing)
@@ -152,8 +168,9 @@ public class TileComponentConfig implements ITileComponent
{
return EMPTY;
}
int index = getConfig(type)[side.ordinal()];
SideConfig sideConfig = getConfig(type);
int index = sideConfig.get(side);
if(index == -1)
{
@@ -161,7 +178,8 @@ public class TileComponentConfig implements ITileComponent
}
else if(index > getOutputs(type).size()-1)
{
index = getConfig(type)[side.ordinal()] = 0;
sideConfig.set(side, (byte) 0);
index = 0;
}
return getOutputs(type).get(index);
@@ -184,8 +202,8 @@ public class TileComponentConfig implements ITileComponent
{
if(nbtTags.getByteArray("config" + type.ordinal()).length > 0)
{
sideConfigs.put(type.ordinal(), nbtTags.getByteArray("config" + type.ordinal()));
ejecting.put(type.ordinal(), nbtTags.getBoolean("ejecting" + type.ordinal()));
sideConfigs.put(type, new SideConfig(nbtTags.getByteArray("config" + type.ordinal())));
ejecting.put(type, nbtTags.getBoolean("ejecting" + type.ordinal()));
}
}
}
@@ -207,9 +225,9 @@ public class TileComponentConfig implements ITileComponent
{
byte[] array = new byte[6];
dataStream.readBytes(array);
sideConfigs.put(type.ordinal(), array);
ejecting.put(type.ordinal(), dataStream.readBoolean());
sideConfigs.put(type, new SideConfig(array));
ejecting.put(type, dataStream.readBoolean());
}
}
@@ -218,8 +236,8 @@ public class TileComponentConfig implements ITileComponent
{
for(TransmissionType type : transmissions)
{
nbtTags.setByteArray("config" + type.ordinal(), sideConfigs.get(type.ordinal()));
nbtTags.setBoolean("ejecting" + type.ordinal(), ejecting.get(type.ordinal()));
nbtTags.setByteArray("config" + type.ordinal(), sideConfigs.get(type).asByteArray());
nbtTags.setBoolean("ejecting" + type.ordinal(), ejecting.get(type));
}
nbtTags.setBoolean("sideDataStored", true);
@@ -237,8 +255,8 @@ public class TileComponentConfig implements ITileComponent
for(TransmissionType type : transmissions)
{
data.add(sideConfigs.get(type.ordinal()));
data.add(ejecting.get(type.ordinal()));
data.add(sideConfigs.get(type).asByteArray());
data.add(ejecting.get(type));
}
}
@@ -247,12 +265,12 @@ public class TileComponentConfig implements ITileComponent
public boolean isEjecting(TransmissionType type)
{
return ejecting.get(type.ordinal());
return ejecting.get(type);
}
public void setEjecting(TransmissionType type, boolean eject)
{
ejecting.put(type.ordinal(), eject);
ejecting.put(type, eject);
MekanismUtils.saveChunk(tileEntity);
}
}
@@ -153,13 +153,18 @@ public class TileComponentEjector implements ITileComponent
List<EnumFacing> outputSides = new ArrayList<EnumFacing>();
ISideConfiguration configurable = (ISideConfiguration)tileEntity;
for(int i = 0; i < configurable.getConfig().getConfig(type).length; i++)
SideConfig sideConfig = configurable.getConfig().getConfig(type);
ArrayList<SideData> outputs = configurable.getConfig().getOutputs(type);
EnumFacing[] facings = MekanismUtils.getBaseOrientations(tileEntity.facing);
for(int i = 0; i < EnumFacing.VALUES.length; i++)
{
EnumFacing side = MekanismUtils.getBaseOrientation(EnumFacing.getFront(i), tileEntity.facing);
if(configurable.getConfig().getConfig(type)[side.ordinal()] == configurable.getConfig().getOutputs(type).indexOf(data))
EnumFacing side = facings[i];
if(sideConfig.get(side) == outputs.indexOf(data))
{
outputSides.add(EnumFacing.getFront(i));
outputSides.add(EnumFacing.VALUES[i]);
}
}
@@ -60,10 +60,10 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
*
* @param soundPath - location of the sound effect
* @param name - full name of this machine
* @param perTick - how much energy this machine uses per tick.
* @param secondaryPerTick - how much secondary energy (fuel) this machine uses per tick.
* @param ticksRequired - how many ticks it takes to smelt an item.
* @param maxEnergy - maximum amount of energy this machine can hold.
* @param baseEnergyUsage - how much energy this machine uses per tick.
* @param ticksRequired - how many ticks it takes to smelt an item.
* @param secondaryPerTick - how much secondary energy (fuel) this machine uses per tick.
*/
public TileEntityAdvancedElectricMachine(String soundPath, String name, double maxEnergy, double baseEnergyUsage, int ticksRequired, int secondaryPerTick)
{
@@ -141,7 +141,7 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
for(TransmissionType transmission : configComponent.transmissions)
{
factory.configComponent.setConfig(transmission, configComponent.getConfig(transmission));
factory.configComponent.setConfig(transmission, configComponent.getConfig(transmission).asByteArray());
factory.configComponent.setEjecting(transmission, configComponent.isEjecting(transmission));
}
@@ -30,10 +30,8 @@ public abstract class TileEntityBasicMachine<INPUT extends MachineInput<INPUT>,
* The foundation of all machines - a simple tile entity with a facing, active state, initialized state, sound effect, and animated texture.
* @param soundPath - location of the sound effect
* @param name - full name of this machine
* @param location - GUI texture path of this machine
* @param perTick - the energy this machine consumes every tick in it's active state
* @param baseTicksRequired - how many ticks it takes to run a cycle
* @param maxEnergy - how much energy this machine can store
* @param baseTicksRequired - how many ticks it takes to run a cycle
*/
public TileEntityBasicMachine(String soundPath, String name, double maxEnergy, double baseEnergyUsage, int upgradeSlot, int baseTicksRequired, ResourceLocation location)
{
@@ -48,6 +46,11 @@ public abstract class TileEntityBasicMachine<INPUT extends MachineInput<INPUT>,
return configComponent.getSidesForData(TransmissionType.ENERGY, facing, 1);
}
@Override
public boolean sideIsConsumer(EnumFacing side) {
return configComponent.hasSideForData(TransmissionType.ENERGY, facing, 1, side);
}
@Override
public int[] getSlotsForFace(EnumFacing side)
{
@@ -107,12 +107,22 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
return EnumSet.noneOf(EnumFacing.class);
}
@Override
public boolean sideIsOutput(EnumFacing side) {
return false;
}
@Override
public EnumSet<EnumFacing> getConsumingSides()
{
return EnumSet.allOf(EnumFacing.class);
}
@Override
public boolean sideIsConsumer(EnumFacing side) {
return true;
}
@Override
public double getMaxOutput()
{
@@ -238,7 +248,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
@Method(modid = "redstoneflux")
public boolean canConnectEnergy(EnumFacing from)
{
return getConsumingSides().contains(from) || getOutputtingSides().contains(from);
return sideIsConsumer(from) || sideIsOutput(from);
}
@Override
@@ -288,27 +298,27 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
@Method(modid = "IC2")
public boolean isTeleporterCompatible(EnumFacing side)
{
return getOutputtingSides().contains(side);
return sideIsOutput(side);
}
@Override
public boolean canOutputEnergy(EnumFacing side)
{
return getOutputtingSides().contains(side);
return sideIsOutput(side);
}
@Override
@Method(modid = "IC2")
public boolean acceptsEnergyFrom(IEnergyEmitter emitter, EnumFacing direction)
{
return getConsumingSides().contains(direction);
return sideIsConsumer(direction);
}
@Override
@Method(modid = "IC2")
public boolean emitsEnergyTo(IEnergyAcceptor receiver, EnumFacing direction)
{
return getOutputtingSides().contains(direction) && receiver instanceof IEnergyConductor;
return sideIsOutput(direction) && receiver instanceof IEnergyConductor;
}
@Override
@@ -349,7 +359,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
@Override
public boolean canReceiveEnergy(EnumFacing side)
{
return getConsumingSides().contains(side);
return sideIsConsumer(side);
}
@Override
@@ -383,12 +393,12 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
@Override
public double acceptEnergy(EnumFacing side, double amount, boolean simulate)
{
if(!(getConsumingSides().contains(side) || side == null))
double toUse = Math.min(getMaxEnergy()-getEnergy(), amount);
if(toUse < 0.0001 || (side != null && !sideIsConsumer(side)))
{
return 0;
}
double toUse = Math.min(getMaxEnergy()-getEnergy(), amount);
if(!simulate)
{
@@ -401,13 +411,13 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
@Override
public double pullEnergy(EnumFacing side, double amount, boolean simulate)
{
if(!(getOutputtingSides().contains(side) || side == null))
double toGive = Math.min(getEnergy(), amount);
if(toGive < 0.0001 || (side != null && !sideIsOutput(side)))
{
return 0;
}
double toGive = Math.min(getEnergy(), amount);
if(!simulate)
{
setEnergy(getEnergy() - toGive);
@@ -423,8 +433,8 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
|| capability == Capabilities.ENERGY_ACCEPTOR_CAPABILITY
|| capability == Capabilities.ENERGY_OUTPUTTER_CAPABILITY
|| capability == Capabilities.TESLA_HOLDER_CAPABILITY
|| (capability == Capabilities.TESLA_CONSUMER_CAPABILITY && getConsumingSides().contains(facing))
|| (capability == Capabilities.TESLA_PRODUCER_CAPABILITY && getOutputtingSides().contains(facing))
|| (capability == Capabilities.TESLA_CONSUMER_CAPABILITY && sideIsConsumer(facing))
|| (capability == Capabilities.TESLA_PRODUCER_CAPABILITY && sideIsOutput(facing))
|| capability == CapabilityEnergy.ENERGY
|| super.hasCapability(capability, facing);
}
@@ -442,8 +452,8 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
}
if(capability == Capabilities.TESLA_HOLDER_CAPABILITY
|| (capability == Capabilities.TESLA_CONSUMER_CAPABILITY && getConsumingSides().contains(facing))
|| (capability == Capabilities.TESLA_PRODUCER_CAPABILITY && getOutputtingSides().contains(facing)))
|| (capability == Capabilities.TESLA_CONSUMER_CAPABILITY && sideIsConsumer(facing))
|| (capability == Capabilities.TESLA_PRODUCER_CAPABILITY && sideIsOutput(facing)))
{
return (T)teslaManager.getWrapper(this, facing);
}
@@ -101,7 +101,7 @@ public abstract class TileEntityElectricMachine<RECIPE extends BasicMachineRecip
for(TransmissionType transmission : configComponent.transmissions)
{
factory.configComponent.setConfig(transmission, configComponent.getConfig(transmission));
factory.configComponent.setConfig(transmission, configComponent.getConfig(transmission).asByteArray());
factory.configComponent.setEjecting(transmission, configComponent.isEjecting(transmission));
}
@@ -21,6 +21,7 @@ import mekanism.common.content.transporter.PathfinderCache;
import mekanism.common.content.transporter.TransitRequest;
import mekanism.common.content.transporter.TransitRequest.TransitResponse;
import mekanism.common.content.transporter.TransporterStack;
import mekanism.common.integration.multipart.MultipartTileNetworkJoiner;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.transmitters.TransporterImpl;
import mekanism.common.transmitters.grid.InventoryNetwork;
@@ -271,6 +272,11 @@ public class TileEntityLogisticalTransporter extends TileEntityTransmitter<TileE
public ArrayList<Object> getSyncPacket(TransporterStack stack, boolean kill)
{
ArrayList<Object> data = new ArrayList<Object>();
if(Mekanism.hooks.MCMPLoaded)
{
MultipartTileNetworkJoiner.addMultipartHeader(this, data, null);
}
data.add(1);
data.add(kill);
@@ -344,7 +350,7 @@ public class TileEntityLogisticalTransporter extends TileEntityTransmitter<TileE
TransporterUtils.incrementColor(getTransmitter());
onPartChanged(null);
PathfinderCache.onChanged(new Coord4D(getPos(), getWorld()));
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(new Coord4D(getPos(), getWorld()), getNetworkedData(new ArrayList())), new Range4D(new Coord4D(getPos(), getWorld())));
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(new Coord4D(getPos(), getWorld()), getNetworkedData(new ArrayList<>())), new Range4D(new Coord4D(getPos(), getWorld())));
player.sendMessage(new TextComponentString(EnumColor.DARK_BLUE + "[Mekanism]" + EnumColor.GREY + " " + LangUtils.localize("tooltip.configurator.toggleColor") + ": " + (getTransmitter().getColor() != null ? getTransmitter().getColor().getColoredName() : EnumColor.BLACK + LangUtils.localize("gui.none"))));
return EnumActionResult.SUCCESS;
@@ -22,6 +22,7 @@ import mekanism.common.block.states.BlockStateTransmitter.TransmitterType;
import mekanism.common.block.states.BlockStateTransmitter.TransmitterType.Size;
import mekanism.common.capabilities.Capabilities;
import mekanism.common.integration.multipart.MultipartMekanism;
import mekanism.common.integration.multipart.MultipartTileNetworkJoiner;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.util.CapabilityUtils;
import mekanism.common.util.MekanismUtils;
@@ -373,6 +374,11 @@ public abstract class TileEntitySidedPipe extends TileEntity implements ITileNet
@Override
public ArrayList<Object> getNetworkedData(ArrayList<Object> data)
{
if(Mekanism.hooks.MCMPLoaded)
{
MultipartTileNetworkJoiner.addMultipartHeader(this, data, null);
}
data.add(currentTransmitterConnections);
data.add(currentAcceptorConnections);
@@ -412,6 +418,14 @@ public abstract class TileEntitySidedPipe extends TileEntity implements ITileNet
return nbtTags;
}
@Override
public NBTTagCompound getUpdateTag()
{
NBTTagCompound nbtTags = super.getUpdateTag();
nbtTags.setInteger("tier", getBaseTier().ordinal());
return nbtTags;
}
protected void onRefresh() {}
public void refreshConnections()
@@ -481,6 +495,13 @@ public abstract class TileEntitySidedPipe extends TileEntity implements ITileNet
super.invalidate();
}
@Override
public void validate()
{
onWorldJoin();
super.validate();
}
@Override
public void onChunkUnload()
{
@@ -615,7 +636,6 @@ public abstract class TileEntitySidedPipe extends TileEntity implements ITileNet
for(EnumFacing side : EnumFacing.values())
{
int ord = side.ordinal();
byte connections = getAllCurrentConnections();
if(connectionMapContainsSide(connections, side))
@@ -28,6 +28,8 @@ public abstract class TileEntityTransmitter<A, N extends DynamicNetwork<A, N>> e
public boolean unloaded = true;
public boolean dataRequest = false;
private N lastClientNetwork = null;
public TileEntityTransmitter()
{
@@ -50,6 +52,10 @@ public abstract class TileEntityTransmitter<A, N extends DynamicNetwork<A, N>> e
{
TransmitterNetworkRegistry.registerOrphanTransmitter(getTransmitter());
}
else if(lastClientNetwork != null)
{
getTransmitter().setTransmitterNetwork(lastClientNetwork);
}
unloaded = false;
}
@@ -90,6 +96,7 @@ public abstract class TileEntityTransmitter<A, N extends DynamicNetwork<A, N>> e
TransmitterNetworkRegistry.invalidateTransmitter(getTransmitter());
}
else {
lastClientNetwork = getTransmitter().getTransmitterNetwork();
getTransmitter().setTransmitterNetwork(null);
}
}
@@ -295,13 +295,13 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyAccept
@Override
public double acceptEnergy(EnumFacing side, double amount, boolean simulate)
{
if(!canReceiveEnergy(side))
double toUse = Math.min(getMaxEnergy() - getEnergy(), amount);
if(toUse < 0.0001 || (side != null && !canReceiveEnergy(side)))
{
return 0;
}
double toUse = Math.min(getMaxEnergy() - getEnergy(), amount);
if(!simulate)
{
setEnergy(getEnergy() + toUse);
@@ -27,40 +27,46 @@ public final class FluidContainerUtils
public static FluidStack extractFluid(FluidTank tileTank, TileEntityContainerBlock tile, int slotID, FluidChecker checker)
{
FluidStack ret = extractFluid(tileTank.getCapacity()-tileTank.getFluidAmount(), tile.inventory.get(slotID), checker);
tile.inventory.set(slotID, FluidUtil.getFluidHandler(tile.inventory.get(slotID)).getContainer());
IFluidHandlerItem handler = FluidUtil.getFluidHandler(tile.inventory.get(slotID));
FluidStack ret = null;
if (handler != null)
{
ret = extractFluid(tileTank.getCapacity() - tileTank.getFluidAmount(), handler, checker);
tile.inventory.set(slotID, handler.getContainer());
}
return ret;
}
public static FluidStack extractFluid(int needed, ItemStack container, FluidChecker checker)
public static FluidStack extractFluid(int needed, IFluidHandlerItem handler, FluidChecker checker)
{
IFluidHandlerItem handler = FluidUtil.getFluidHandler(container);
if (handler == null)
{
return null;
}
FluidStack fluidStack = handler.drain(Integer.MAX_VALUE, false);
if(handler == null || FluidUtil.getFluidContained(container) == null)
if(fluidStack == null)
{
return null;
}
if(checker != null && !checker.isValid(FluidUtil.getFluidContained(container).getFluid()))
if(checker != null && !checker.isValid(fluidStack.getFluid()))
{
return null;
}
FluidStack ret = handler.drain(needed, true);
return ret;
return handler.drain(needed, true);
}
public static int insertFluid(FluidTank tileTank, ItemStack container)
{
return insertFluid(tileTank.getFluid(), container);
return insertFluid(tileTank.getFluid(), FluidUtil.getFluidHandler(container));
}
public static int insertFluid(FluidStack fluid, ItemStack container)
public static int insertFluid(FluidStack fluid, IFluidHandler handler)
{
IFluidHandler handler = FluidUtil.getFluidHandler(container);
if(fluid == null)
if(fluid == null || handler == null)
{
return 0;
}
@@ -79,8 +85,13 @@ public final class FluidContainerUtils
{
ItemStack inputCopy = StackUtils.size(inventory.get(inSlot).copy(), 1);
int drained = insertFluid(stack, inputCopy);
inputCopy = FluidUtil.getFluidHandler(inputCopy).getContainer();
IFluidHandlerItem handler = FluidUtil.getFluidHandler(inputCopy);
int drained = 0;
if (handler != null)
{
drained = insertFluid(stack, handler);
inputCopy = handler.getContainer();
}
if(!inventory.get(outSlot).isEmpty() && (!ItemHandlerHelper.canItemStacksStack(inventory.get(outSlot), inputCopy) || inventory.get(outSlot).getCount() == inventory.get(outSlot).getMaxStackSize()))
{
@@ -120,8 +131,14 @@ public final class FluidContainerUtils
{
final Fluid storedFinal = stored != null ? stored.getFluid() : null;
final ItemStack input = StackUtils.size(inventory.get(inSlot).copy(), 1);
final IFluidHandlerItem handler = FluidUtil.getFluidHandler(input);
if (handler == null)
{
return stored;
}
FluidStack ret = extractFluid(needed, input, new FluidChecker() {
FluidStack ret = extractFluid(needed, handler, new FluidChecker() {
@Override
public boolean isValid(Fluid f)
{
@@ -129,7 +146,7 @@ public final class FluidContainerUtils
}
});
ItemStack inputCopy = FluidUtil.getFluidHandler(input).getContainer();
ItemStack inputCopy = handler.getContainer();
if(FluidUtil.getFluidContained(inputCopy) == null && !inputCopy.isEmpty())
{
@@ -21,11 +21,7 @@ import mekanism.api.IMekWrench;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasStack;
import mekanism.api.transmitters.TransmissionType;
import mekanism.common.Mekanism;
import mekanism.common.MekanismBlocks;
import mekanism.common.MekanismFluids;
import mekanism.common.MekanismItems;
import mekanism.common.OreDictCache;
import mekanism.common.*;
import mekanism.common.Tier.BaseTier;
import mekanism.common.Tier.BinTier;
import mekanism.common.Tier.EnergyCubeTier;
@@ -34,8 +30,6 @@ import mekanism.common.Tier.FluidTankTier;
import mekanism.common.Tier.GasTankTier;
import mekanism.common.Tier.InductionCellTier;
import mekanism.common.Tier.InductionProviderTier;
import mekanism.common.Upgrade;
import mekanism.common.Version;
import mekanism.common.base.IActiveState;
import mekanism.common.base.IFactory;
import mekanism.common.base.IFactory.RecipeType;
@@ -59,6 +53,7 @@ import mekanism.common.network.PacketPersonalChest.PersonalChestPacketType;
import mekanism.common.tile.TileEntityAdvancedBoundingBlock;
import mekanism.common.tile.TileEntityBoundingBlock;
import mekanism.common.tile.TileEntityPersonalChest;
import mekanism.common.tile.component.SideConfig;
import mekanism.common.util.UnitDisplayUtils.ElectricUnit;
import mekanism.common.util.UnitDisplayUtils.TemperatureUnit;
import net.minecraft.block.Block;
@@ -460,7 +455,28 @@ public final class MekanismUtils
}
/**
* Returns an integer facing that converts a world-based orientation to a machine-based oriention.
* Pre-calculated cache of translated block orientations
*/
private static final EnumFacing[][] baseOrientations = new EnumFacing[EnumFacing.VALUES.length][EnumFacing.VALUES.length];
static {
for (int blockFacing = 0; blockFacing < EnumFacing.VALUES.length; blockFacing++) {
for (int side = 0; side < EnumFacing.VALUES.length; side++) {
baseOrientations[blockFacing][side] = getBaseOrientation(EnumFacing.VALUES[side], EnumFacing.VALUES[blockFacing]);
}
}
}
/**
* Returns the sides in the modified order relative to the machine-based orientation.
* @param blockFacing - what orientation the block is facing
* @return EnumFacing.VALUES, translated to machine orientation
*/
public static EnumFacing[] getBaseOrientations(EnumFacing blockFacing) {
return baseOrientations[blockFacing.ordinal()];
}
/**
* Returns an integer facing that converts a world-based orientation to a machine-based orientation.
* @param side - world based
* @param blockFacing - what orientation the block is facing
* @return machine orientation
@@ -547,21 +563,22 @@ public final class MekanismUtils
*/
public static void incrementOutput(ISideConfiguration config, TransmissionType type, EnumFacing direction)
{
int side = direction.ordinal();
int max = config.getConfig().getOutputs(type).size()-1;
int current = config.getConfig().getOutputs(type).indexOf(config.getConfig().getOutputs(type).get(config.getConfig().getConfig(type)[side]));
ArrayList<SideData> outputs = config.getConfig().getOutputs(type);
SideConfig sideConfig = config.getConfig().getConfig(type);
int max = outputs.size() - 1;
int current = outputs.indexOf(outputs.get(sideConfig.get(direction)));
if(current < max)
{
config.getConfig().getConfig(type)[side] = (byte)(current+1);
sideConfig.set(direction, (byte) (current+1));
}
else if(current == max)
{
config.getConfig().getConfig(type)[side] = 0;
sideConfig.set(direction, (byte) 0);
}
TileEntity tile = (TileEntity)config;
assert config instanceof TileEntity;
TileEntity tile = (TileEntity) config;
tile.markDirty();
}
@@ -573,19 +590,21 @@ public final class MekanismUtils
*/
public static void decrementOutput(ISideConfiguration config, TransmissionType type, EnumFacing direction)
{
int side = direction.ordinal();
int max = config.getConfig().getOutputs(type).size()-1;
int current = config.getConfig().getOutputs(type).indexOf(config.getConfig().getOutputs(type).get(config.getConfig().getConfig(type)[side]));
ArrayList<SideData> outputs = config.getConfig().getOutputs(type);
SideConfig sideConfig = config.getConfig().getConfig(type);
int max = outputs.size()-1;
int current = outputs.indexOf(outputs.get(sideConfig.get(direction)));
if(current > 0)
{
config.getConfig().getConfig(type)[side] = (byte)(current-1);
sideConfig.set(direction, (byte)(current - 1));
}
else if(current == 0)
{
config.getConfig().getConfig(type)[side] = (byte)max;
sideConfig.set(direction, (byte)max);
}
assert config instanceof TileEntity;
TileEntity tile = (TileEntity)config;
tile.markDirty();
}
@@ -25,6 +25,11 @@ public class TileEntityAdvancedSolarGenerator extends TileEntitySolarGenerator i
return EnumSet.of(facing);
}
@Override
public boolean sideIsOutput(EnumFacing side) {
return side == facing;
}
@Override
public void onPlace()
{
@@ -122,12 +122,22 @@ public abstract class TileEntityGenerator extends TileEntityNoisyBlock implement
return EnumSet.noneOf(EnumFacing.class);
}
@Override
public boolean sideIsConsumer(EnumFacing side) {
return false;
}
@Override
public EnumSet<EnumFacing> getOutputtingSides()
{
return EnumSet.of(facing);
}
@Override
public boolean sideIsOutput(EnumFacing side) {
return side == facing;
}
/**
* Whether or not this generator can operate.
* @return if the generator can operate
@@ -194,6 +194,11 @@ public class TileEntitySolarGenerator extends TileEntityGenerator
return EnumSet.of(EnumFacing.getFront(0));
}
@Override
public boolean sideIsOutput(EnumFacing side) {
return side == EnumFacing.DOWN;
}
@Override
public boolean renderUpdate()
{
@@ -82,12 +82,22 @@ public abstract class TileEntityReactorBlock extends TileEntityElectricBlock
return EnumSet.noneOf(EnumFacing.class);
}
@Override
public boolean sideIsOutput(EnumFacing side) {
return false;
}
@Override
public EnumSet<EnumFacing> getConsumingSides()
{
return EnumSet.noneOf(EnumFacing.class);
}
@Override
public boolean sideIsConsumer(EnumFacing side) {
return false;
}
@Override
public void onChunkUnload()
{
@@ -290,12 +290,22 @@ public class TileEntityReactorPort extends TileEntityReactorBlock implements IFl
return EnumSet.allOf(EnumFacing.class);
}
@Override
public boolean sideIsOutput(EnumFacing side) {
return true;
}
@Override
public EnumSet<EnumFacing> getConsumingSides()
{
return EnumSet.noneOf(EnumFacing.class);
}
@Override
public boolean sideIsConsumer(EnumFacing side) {
return false;
}
@Override
public double getMaxOutput()
{
@@ -77,7 +77,7 @@ public class TileEntityTurbineValve extends TileEntityTurbineCasing implements I
{
if(structure != null)
{
EnumSet set = EnumSet.allOf(EnumFacing.class);
EnumSet<EnumFacing> set = EnumSet.allOf(EnumFacing.class);
for(EnumFacing side : EnumFacing.VALUES)
{
@@ -93,11 +93,25 @@ public class TileEntityTurbineValve extends TileEntityTurbineCasing implements I
return EnumSet.noneOf(EnumFacing.class);
}
@Override
public boolean sideIsOutput(EnumFacing side) {
if (structure != null)
{
return !structure.locations.contains(Coord4D.get(this).offset(side));
}
return false;
}
@Override
public EnumSet<EnumFacing> getConsumingSides()
{
return EnumSet.noneOf(EnumFacing.class);
}
@Override
public boolean sideIsConsumer(EnumFacing side) {
return false;
}
@Method(modid = "IC2")
public void register()
@@ -185,7 +199,7 @@ public class TileEntityTurbineValve extends TileEntityTurbineCasing implements I
@Method(modid = "redstoneflux")
public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate)
{
if(getOutputtingSides().contains(from))
if(sideIsOutput(from))
{
double toSend = Math.min(getEnergy(), Math.min(getMaxOutput(), maxExtract*general.FROM_RF));
@@ -259,7 +273,7 @@ public class TileEntityTurbineValve extends TileEntityTurbineCasing implements I
@Override
public boolean canOutputEnergy(EnumFacing side)
{
return getOutputtingSides().contains(side);
return sideIsOutput(side);
}
@Override
@@ -273,7 +287,7 @@ public class TileEntityTurbineValve extends TileEntityTurbineCasing implements I
@Method(modid = "IC2")
public boolean emitsEnergyTo(IEnergyAcceptor receiver, EnumFacing direction)
{
return getOutputtingSides().contains(direction) && receiver instanceof IEnergyConductor;
return sideIsOutput(direction) && receiver instanceof IEnergyConductor;
}
@Override
@@ -351,13 +365,13 @@ public class TileEntityTurbineValve extends TileEntityTurbineCasing implements I
@Override
public double pullEnergy(EnumFacing side, double amount, boolean simulate)
{
if(!getOutputtingSides().contains(side))
double toGive = Math.min(getEnergy(), amount);
if(toGive < 0.0001 || (side != null && !sideIsOutput(side)))
{
return 0;
}
double toGive = Math.min(getEnergy(), amount);
if(!simulate)
{
setEnergy(getEnergy() - toGive);
@@ -478,7 +492,7 @@ public class TileEntityTurbineValve extends TileEntityTurbineCasing implements I
|| capability == Capabilities.ENERGY_STORAGE_CAPABILITY
|| capability == Capabilities.ENERGY_OUTPUTTER_CAPABILITY
|| capability == Capabilities.TESLA_HOLDER_CAPABILITY
|| (capability == Capabilities.TESLA_PRODUCER_CAPABILITY && getOutputtingSides().contains(facing))
|| (capability == Capabilities.TESLA_PRODUCER_CAPABILITY && sideIsOutput(facing))
|| capability == CapabilityEnergy.ENERGY)
{
return true;
@@ -507,7 +521,7 @@ public class TileEntityTurbineValve extends TileEntityTurbineCasing implements I
}
if(capability == Capabilities.TESLA_HOLDER_CAPABILITY
|| (capability == Capabilities.TESLA_PRODUCER_CAPABILITY && getOutputtingSides().contains(facing)))
|| (capability == Capabilities.TESLA_PRODUCER_CAPABILITY && sideIsOutput(facing)))
{
return (T)teslaManager.getWrapper(this, facing);
}