use of mekanism.common.tile.base.TileEntityMekanism in project Mekanism by mekanism.
the class GuiGauge method renderToolTip.
@Override
public void renderToolTip(@Nonnull MatrixStack matrix, int mouseX, int mouseY) {
super.renderToolTip(matrix, mouseX, mouseY);
ItemStack stack = minecraft.player.inventory.getCarried();
EnumColor color = getGaugeColor().getColor();
if (!stack.isEmpty() && stack.getItem() instanceof ItemConfigurator && color != null) {
if (gui() instanceof GuiMekanismTile) {
TileEntityMekanism tile = ((GuiMekanismTile<?, ?>) gui()).getTileEntity();
if (tile instanceof ISideConfiguration && getTransmission() != null) {
DataType dataType = null;
ConfigInfo config = ((ISideConfiguration) tile).getConfig().getConfig(getTransmission());
if (config != null) {
Set<DataType> supportedDataTypes = config.getSupportedDataTypes();
for (DataType type : supportedDataTypes) {
if (type.getColor() == color) {
dataType = type;
break;
}
}
}
if (dataType == null) {
displayTooltip(matrix, MekanismLang.GENERIC_PARENTHESIS.translateColored(color, color.getName()), mouseX, mouseY);
} else {
displayTooltip(matrix, MekanismLang.GENERIC_WITH_PARENTHESIS.translateColored(color, dataType, color.getName()), mouseX, mouseY);
}
}
}
} else {
List<ITextComponent> list = new ArrayList<>();
if (getLabel() != null) {
list.add(getLabel());
}
list.addAll(getTooltipText());
displayTooltips(matrix, list, mouseX, mouseY);
}
}
use of mekanism.common.tile.base.TileEntityMekanism in project Mekanism by mekanism.
the class BlockMekanism method getPickBlock.
@Nonnull
@Override
public ItemStack getPickBlock(@Nonnull BlockState state, RayTraceResult target, @Nonnull IBlockReader world, @Nonnull BlockPos pos, PlayerEntity player) {
ItemStack itemStack = new ItemStack(this);
TileEntityMekanism tile = WorldUtils.getTileEntity(TileEntityMekanism.class, world, pos);
if (tile == null) {
return itemStack;
}
// TODO: Some of the data doesn't get properly "picked", because there are cases such as before opening the GUI where
// the server doesn't bother syncing the data to the client. For example with what frequencies there are
Item item = itemStack.getItem();
if (tile.getFrequencyComponent().hasCustomFrequencies()) {
tile.getFrequencyComponent().write(ItemDataUtils.getDataMap(itemStack));
}
if (item instanceof ISecurityItem && tile.hasSecurity()) {
ISecurityItem securityItem = (ISecurityItem) item;
securityItem.setOwnerUUID(itemStack, tile.getOwnerUUID());
securityItem.setSecurity(itemStack, tile.getSecurityMode());
}
if (tile.supportsUpgrades()) {
tile.getComponent().write(ItemDataUtils.getDataMap(itemStack));
}
if (tile instanceof ISideConfiguration) {
ISideConfiguration config = (ISideConfiguration) tile;
config.getConfig().write(ItemDataUtils.getDataMap(itemStack));
config.getEjector().write(ItemDataUtils.getDataMap(itemStack));
}
if (tile instanceof ISustainedData) {
((ISustainedData) tile).writeSustainedData(itemStack);
}
if (tile.supportsRedstone()) {
ItemDataUtils.setInt(itemStack, NBTConstants.CONTROL_TYPE, tile.getControlType().ordinal());
}
for (SubstanceType type : EnumUtils.SUBSTANCES) {
if (tile.handles(type)) {
ItemDataUtils.setList(itemStack, type.getContainerTag(), DataHandlerUtils.writeContainers(type.getContainers(tile)));
}
}
if (item instanceof ISustainedInventory && tile.persistInventory() && tile.getSlots() > 0) {
((ISustainedInventory) item).setInventory(tile.getInventory(), itemStack);
}
return itemStack;
}
use of mekanism.common.tile.base.TileEntityMekanism in project Mekanism by mekanism.
the class BlockMekanism method getDrops.
@Nonnull
@Override
@Deprecated
public List<ItemStack> getDrops(@Nonnull BlockState state, @Nonnull LootContext.Builder builder) {
List<ItemStack> drops = super.getDrops(state, builder);
// Check if we need to clear any radioactive materials from the stored tanks as those will be dumped via the tile being removed
if (state.getBlock() instanceof IHasTileEntity) {
TileEntity tile = ((IHasTileEntity<?>) state.getBlock()).getTileType().create();
if (tile instanceof TileEntityMekanism) {
TileEntityMekanism mekTile = (TileEntityMekanism) tile;
// Skip tiles that have no tanks and skip chemical creative tanks
if (!mekTile.getGasTanks(null).isEmpty() && (!(mekTile instanceof TileEntityChemicalTank) || ((TileEntityChemicalTank) mekTile).getTier() != ChemicalTankTier.CREATIVE)) {
for (ItemStack drop : drops) {
ListNBT gasTankList = ItemDataUtils.getList(drop, NBTConstants.GAS_TANKS);
if (!gasTankList.isEmpty()) {
int count = DataHandlerUtils.getMaxId(gasTankList, NBTConstants.TANK);
List<IGasTank> tanks = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
tanks.add(ChemicalTankBuilder.GAS.createDummy(Long.MAX_VALUE));
}
DataHandlerUtils.readContainers(tanks, gasTankList);
boolean hasRadioactive = false;
for (IGasTank tank : tanks) {
if (!tank.isEmpty() && tank.getStack().has(GasAttributes.Radiation.class)) {
// If the tank isn't empty and has a radioactive gas in it, clear the tank and mark we need to update the item
hasRadioactive = true;
tank.setEmpty();
}
}
if (hasRadioactive) {
// If the item has any gas tanks stored, check if any have radioactive substances in them
// and if so clear them out
ListNBT newGasTankList = DataHandlerUtils.writeContainers(tanks);
if (newGasTankList.isEmpty()) {
// If the list is now empty remove it
ItemDataUtils.removeData(drop, NBTConstants.GAS_TANKS);
} else {
// Otherwise, update the list
ItemDataUtils.setList(drop, NBTConstants.GAS_TANKS, newGasTankList);
}
}
}
}
}
}
}
return drops;
}
use of mekanism.common.tile.base.TileEntityMekanism in project Mekanism by mekanism.
the class PacketGuiButtonPress method handle.
@Override
public void handle(NetworkEvent.Context context) {
ServerPlayerEntity player = context.getSender();
if (player == null) {
return;
}
if (type == Type.ENTITY) {
Entity entity = player.level.getEntity(entityID);
if (entity != null) {
INamedContainerProvider provider = entityButton.getProvider(entity);
if (provider != null) {
// Ensure valid data
NetworkHooks.openGui(player, provider, buf -> buf.writeVarInt(entityID));
}
}
} else if (type == Type.TILE) {
TileEntityMekanism tile = WorldUtils.getTileEntity(TileEntityMekanism.class, player.level, tilePosition);
if (tile != null) {
INamedContainerProvider provider = tileButton.getProvider(tile, extra);
if (provider != null) {
// Ensure valid data
NetworkHooks.openGui(player, provider, buf -> {
buf.writeBlockPos(tilePosition);
buf.writeVarInt(extra);
});
}
}
} else if (type == Type.ITEM) {
ItemStack stack = player.getItemInHand(hand);
if (stack.getItem() instanceof IGuiItem) {
INamedContainerProvider provider = itemButton.getProvider(stack, hand);
if (provider != null) {
NetworkHooks.openGui(player, provider, buf -> {
buf.writeEnum(hand);
buf.writeItem(stack);
});
}
}
}
}
use of mekanism.common.tile.base.TileEntityMekanism in project Mekanism by mekanism.
the class EnergyRecipeData method applyToStack.
@Override
public boolean applyToStack(ItemStack stack) {
if (energyContainers.isEmpty()) {
return true;
}
Item item = stack.getItem();
Optional<IStrictEnergyHandler> capability = stack.getCapability(Capabilities.STRICT_ENERGY_CAPABILITY).resolve();
List<IEnergyContainer> energyContainers = new ArrayList<>();
if (capability.isPresent()) {
IStrictEnergyHandler energyHandler = capability.get();
for (int container = 0; container < energyHandler.getEnergyContainerCount(); container++) {
energyContainers.add(BasicEnergyContainer.create(energyHandler.getMaxEnergy(container), null));
}
} else if (item instanceof BlockItem) {
TileEntityMekanism tile = getTileFromBlock(((BlockItem) item).getBlock());
if (tile == null || !tile.handles(SubstanceType.ENERGY)) {
// Something went wrong
return false;
}
for (int container = 0; container < tile.getEnergyContainerCount(); container++) {
energyContainers.add(BasicEnergyContainer.create(tile.getMaxEnergy(container), null));
}
} else {
return false;
}
if (energyContainers.isEmpty()) {
// We don't actually have any tanks in the output
return true;
}
IMekanismStrictEnergyHandler outputHandler = new IMekanismStrictEnergyHandler() {
@Nonnull
@Override
public List<IEnergyContainer> getEnergyContainers(@Nullable Direction side) {
return energyContainers;
}
@Override
public void onContentsChanged() {
}
};
boolean hasData = false;
for (IEnergyContainer energyContainer : this.energyContainers) {
if (!energyContainer.isEmpty()) {
hasData = true;
if (!outputHandler.insertEnergy(energyContainer.getEnergy(), Action.EXECUTE).isZero()) {
// If we have a remainder, stop trying to insert as our upgraded item's buffer is just full
break;
}
}
}
if (hasData) {
// We managed to transfer it all into valid slots, so save it to the stack
ItemDataUtils.setList(stack, NBTConstants.ENERGY_CONTAINERS, DataHandlerUtils.writeContainers(energyContainers));
}
return true;
}
Aggregations