use of mekanism.common.tile.component.ITileComponent in project Mekanism by mekanism.
the class TileEntityFluidTank method parseUpgradeData.
@Override
public void parseUpgradeData(@Nonnull IUpgradeData upgradeData) {
if (upgradeData instanceof FluidTankUpgradeData) {
FluidTankUpgradeData data = (FluidTankUpgradeData) upgradeData;
redstone = data.redstone;
inputSlot.setStack(data.inputSlot.getStack());
outputSlot.setStack(data.outputSlot.getStack());
editMode = data.editMode;
fluidTank.setStack(data.stored);
for (ITileComponent component : getComponents()) {
component.read(data.components);
}
} else {
super.parseUpgradeData(upgradeData);
}
}
use of mekanism.common.tile.component.ITileComponent in project Mekanism by mekanism.
the class TileEntityChemicalTank method parseUpgradeData.
@Override
public void parseUpgradeData(@Nonnull IUpgradeData upgradeData) {
if (upgradeData instanceof ChemicalTankUpgradeData) {
ChemicalTankUpgradeData data = (ChemicalTankUpgradeData) upgradeData;
redstone = data.redstone;
setControlType(data.controlType);
drainSlot.setStack(data.drainSlot.getStack());
fillSlot.setStack(data.fillSlot.getStack());
dumping = data.dumping;
getGasTank().setStack(data.storedGas);
getInfusionTank().setStack(data.storedInfusion);
getPigmentTank().setStack(data.storedPigment);
getSlurryTank().setStack(data.storedSlurry);
for (ITileComponent component : getComponents()) {
component.read(data.components);
}
} else {
super.parseUpgradeData(upgradeData);
}
}
use of mekanism.common.tile.component.ITileComponent in project Mekanism by mekanism.
the class TileEntityEnergyCube method parseUpgradeData.
@Override
public void parseUpgradeData(@Nonnull IUpgradeData upgradeData) {
if (upgradeData instanceof EnergyCubeUpgradeData) {
EnergyCubeUpgradeData data = (EnergyCubeUpgradeData) upgradeData;
redstone = data.redstone;
setControlType(data.controlType);
getEnergyContainer().setEnergy(data.energyContainer.getEnergy());
chargeSlot.setStack(data.chargeSlot.getStack());
// Copy the contents using NBT so that if it is not actually valid due to a reload we don't crash
dischargeSlot.deserializeNBT(data.dischargeSlot.serializeNBT());
for (ITileComponent component : getComponents()) {
component.read(data.components);
}
} else {
super.parseUpgradeData(upgradeData);
}
}
use of mekanism.common.tile.component.ITileComponent in project Mekanism by mekanism.
the class TileEntityMekanism method addContainerTrackers.
@Override
public void addContainerTrackers(MekanismContainer container) {
// setup dynamic container syncing
SyncMapper.INSTANCE.setup(container, getClass(), () -> this);
for (ITileComponent component : components) {
component.trackForMainContainer(container);
}
if (supportsRedstone()) {
container.track(SyncableEnum.create(RedstoneControl::byIndexStatic, RedstoneControl.DISABLED, () -> controlType, value -> controlType = value));
}
boolean isClient = isRemote();
if (canHandleGas() && handles(SubstanceType.GAS)) {
List<IGasTank> gasTanks = getGasTanks(null);
for (IGasTank gasTank : gasTanks) {
container.track(SyncableGasStack.create(gasTank, isClient));
}
}
if (canHandleInfusion() && handles(SubstanceType.INFUSION)) {
List<IInfusionTank> infusionTanks = getInfusionTanks(null);
for (IInfusionTank infusionTank : infusionTanks) {
container.track(SyncableInfusionStack.create(infusionTank, isClient));
}
}
if (canHandlePigment() && handles(SubstanceType.PIGMENT)) {
List<IPigmentTank> pigmentTanks = getPigmentTanks(null);
for (IPigmentTank pigmentTank : pigmentTanks) {
container.track(SyncablePigmentStack.create(pigmentTank, isClient));
}
}
if (canHandleSlurry() && handles(SubstanceType.SLURRY)) {
List<ISlurryTank> slurryTanks = getSlurryTanks(null);
for (ISlurryTank slurryTank : slurryTanks) {
container.track(SyncableSlurryStack.create(slurryTank, isClient));
}
}
if (canHandleFluid() && handles(SubstanceType.FLUID)) {
List<IExtendedFluidTank> fluidTanks = getFluidTanks(null);
for (IExtendedFluidTank fluidTank : fluidTanks) {
container.track(SyncableFluidStack.create(fluidTank, isClient));
}
}
if (canHandleHeat() && handles(SubstanceType.HEAT)) {
List<IHeatCapacitor> heatCapacitors = getHeatCapacitors(null);
for (IHeatCapacitor capacitor : heatCapacitors) {
container.track(SyncableDouble.create(capacitor::getHeat, capacitor::setHeat));
if (capacitor instanceof BasicHeatCapacitor) {
container.track(SyncableDouble.create(capacitor::getHeatCapacity, capacity -> ((BasicHeatCapacitor) capacitor).setHeatCapacity(capacity, false)));
}
}
}
if (canHandleEnergy() && handles(SubstanceType.ENERGY)) {
container.track(SyncableFloatingLong.create(this::getInputRate, this::setInputRate));
List<IEnergyContainer> energyContainers = getEnergyContainers(null);
for (IEnergyContainer energyContainer : energyContainers) {
container.track(SyncableFloatingLong.create(energyContainer::getEnergy, energyContainer::setEnergy));
if (energyContainer instanceof MachineEnergyContainer) {
MachineEnergyContainer<?> machineEnergy = (MachineEnergyContainer<?>) energyContainer;
if (supportsUpgrades() || machineEnergy.adjustableRates()) {
container.track(SyncableFloatingLong.create(machineEnergy::getMaxEnergy, machineEnergy::setMaxEnergy));
container.track(SyncableFloatingLong.create(machineEnergy::getEnergyPerTick, machineEnergy::setEnergyPerTick));
}
}
}
}
}
use of mekanism.common.tile.component.ITileComponent in project Mekanism by mekanism.
the class TileEntityMekanism method load.
@Override
public void load(@Nonnull BlockState state, @Nonnull CompoundNBT nbtTags) {
super.load(state, nbtTags);
NBTUtils.setBooleanIfPresent(nbtTags, NBTConstants.REDSTONE, value -> redstone = value);
for (ITileComponent component : components) {
component.read(nbtTags);
}
loadGeneralPersistentData(nbtTags);
if (hasInventory() && persistInventory()) {
DataHandlerUtils.readContainers(getInventorySlots(null), nbtTags.getList(NBTConstants.ITEMS, NBT.TAG_COMPOUND));
}
for (SubstanceType type : EnumUtils.SUBSTANCES) {
if (type.canHandle(this) && persists(type)) {
type.read(this, nbtTags);
}
}
if (isActivatable()) {
NBTUtils.setBooleanIfPresent(nbtTags, NBTConstants.ACTIVE_STATE, value -> currentActive = value);
NBTUtils.setIntIfPresent(nbtTags, NBTConstants.UPDATE_DELAY, value -> updateDelay = value);
}
if (supportsComparator()) {
NBTUtils.setIntIfPresent(nbtTags, NBTConstants.CURRENT_REDSTONE, value -> currentRedstoneLevel = value);
}
}
Aggregations