Search in sources :

Example 1 with TileEntityMekanism

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);
    }
}
Also used : TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) EnumColor(mekanism.api.text.EnumColor) ITextComponent(net.minecraft.util.text.ITextComponent) ArrayList(java.util.ArrayList) ItemConfigurator(mekanism.common.item.ItemConfigurator) DataType(mekanism.common.tile.component.config.DataType) ItemStack(net.minecraft.item.ItemStack) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) GuiMekanismTile(mekanism.client.gui.GuiMekanismTile) ISideConfiguration(mekanism.common.tile.interfaces.ISideConfiguration)

Example 2 with TileEntityMekanism

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;
}
Also used : TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) Item(net.minecraft.item.Item) ISecurityItem(mekanism.common.lib.security.ISecurityItem) ISecurityItem(mekanism.common.lib.security.ISecurityItem) ISustainedInventory(mekanism.common.tile.interfaces.ISustainedInventory) SubstanceType(mekanism.common.tile.base.SubstanceType) ItemStack(net.minecraft.item.ItemStack) ISustainedData(mekanism.common.tile.interfaces.ISustainedData) ISideConfiguration(mekanism.common.tile.interfaces.ISideConfiguration) Nonnull(javax.annotation.Nonnull)

Example 3 with TileEntityMekanism

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;
}
Also used : TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) IHasTileEntity(mekanism.common.block.interfaces.IHasTileEntity) IGasTank(mekanism.api.chemical.gas.IGasTank) ArrayList(java.util.ArrayList) IHasTileEntity(mekanism.common.block.interfaces.IHasTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ListNBT(net.minecraft.nbt.ListNBT) TileEntityChemicalTank(mekanism.common.tile.TileEntityChemicalTank) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 4 with TileEntityMekanism

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);
                });
            }
        }
    }
}
Also used : TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) TileEntityInductionCasing(mekanism.common.tile.multiblock.TileEntityInductionCasing) IGuiItem(mekanism.common.item.interfaces.IGuiItem) Entity(net.minecraft.entity.Entity) Attribute(mekanism.common.block.attribute.Attribute) BiFunction(java.util.function.BiFunction) INamedContainerProvider(net.minecraft.inventory.container.INamedContainerProvider) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) BlockPos(net.minecraft.util.math.BlockPos) Function(java.util.function.Function) ItemStack(net.minecraft.item.ItemStack) Block(net.minecraft.block.Block) WorldUtils(mekanism.common.util.WorldUtils) NetworkHooks(net.minecraftforge.fml.network.NetworkHooks) MekanismContainerTypes(mekanism.common.registries.MekanismContainerTypes) MekanismLang(mekanism.common.MekanismLang) TileEntity(net.minecraft.tileentity.TileEntity) Hand(net.minecraft.util.Hand) IMekanismPacket(mekanism.common.network.IMekanismPacket) TileEntityBoilerCasing(mekanism.common.tile.multiblock.TileEntityBoilerCasing) AttributeGui(mekanism.common.block.attribute.AttributeGui) PacketBuffer(net.minecraft.network.PacketBuffer) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) IGuiItem(mekanism.common.item.interfaces.IGuiItem) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) INamedContainerProvider(net.minecraft.inventory.container.INamedContainerProvider) ItemStack(net.minecraft.item.ItemStack)

Example 5 with TileEntityMekanism

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;
}
Also used : TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) ArrayList(java.util.ArrayList) IMekanismStrictEnergyHandler(mekanism.api.energy.IMekanismStrictEnergyHandler) BlockItem(net.minecraft.item.BlockItem) Direction(net.minecraft.util.Direction) IStrictEnergyHandler(mekanism.api.energy.IStrictEnergyHandler) Item(net.minecraft.item.Item) BlockItem(net.minecraft.item.BlockItem) IEnergyContainer(mekanism.api.energy.IEnergyContainer) Nullable(javax.annotation.Nullable)

Aggregations

TileEntityMekanism (mekanism.common.tile.base.TileEntityMekanism)15 ItemStack (net.minecraft.item.ItemStack)9 Nonnull (javax.annotation.Nonnull)8 Item (net.minecraft.item.Item)6 TileEntity (net.minecraft.tileentity.TileEntity)6 ArrayList (java.util.ArrayList)5 ISideConfiguration (mekanism.common.tile.interfaces.ISideConfiguration)5 Block (net.minecraft.block.Block)5 Nullable (javax.annotation.Nullable)4 SubstanceType (mekanism.common.tile.base.SubstanceType)4 ISustainedInventory (mekanism.common.tile.interfaces.ISustainedInventory)4 PlayerEntity (net.minecraft.entity.player.PlayerEntity)4 BlockItem (net.minecraft.item.BlockItem)4 IEnergyContainer (mekanism.api.energy.IEnergyContainer)3 ISustainedData (mekanism.common.tile.interfaces.ISustainedData)3 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)3 Direction (net.minecraft.util.Direction)3 BlockPos (net.minecraft.util.math.BlockPos)3 World (net.minecraft.world.World)3 List (java.util.List)2