Search in sources :

Example 1 with TileEntitySecurityDesk

use of mekanism.common.tile.TileEntitySecurityDesk in project Mekanism by mekanism.

the class BlockMekanism method setPlacedBy.

@Override
public void setPlacedBy(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable LivingEntity placer, @Nonnull ItemStack stack) {
    super.setPlacedBy(world, pos, state, placer, stack);
    TileEntityMekanism tile = WorldUtils.getTileEntity(TileEntityMekanism.class, world, pos);
    if (tile == null) {
        return;
    }
    if (tile.supportsRedstone()) {
        tile.redstone = world.hasNeighborSignal(pos);
    }
    tile.onPlace();
    // Handle item
    Item item = stack.getItem();
    setTileData(world, pos, state, placer, stack, tile);
    // but there is a good chance a lot of this stuff has no real reason to need to be set on the client side at all
    if (!world.isClientSide && tile.getFrequencyComponent().hasCustomFrequencies()) {
        tile.getFrequencyComponent().read(ItemDataUtils.getDataMap(stack));
    }
    if (tile instanceof TileEntitySecurityDesk && placer != null) {
        tile.getSecurity().setOwnerUUID(placer.getUUID());
    }
    if (item instanceof ISecurityItem && tile.hasSecurity()) {
        ISecurityItem securityItem = (ISecurityItem) item;
        tile.setSecurityMode(securityItem.getSecurity(stack));
        UUID ownerUUID = securityItem.getOwnerUUID(stack);
        if (ownerUUID != null) {
            tile.getSecurity().setOwnerUUID(ownerUUID);
        } else if (placer != null) {
            tile.getSecurity().setOwnerUUID(placer.getUUID());
            if (!world.isClientSide) {
                // If the machine doesn't already have an owner, make sure we portray this
                Mekanism.packetHandler.sendToAll(new PacketSecurityUpdate(placer.getUUID(), null));
            }
        }
    }
    if (tile.supportsUpgrades()) {
        // The read method validates that data is stored
        tile.getComponent().read(ItemDataUtils.getDataMap(stack));
    }
    if (tile instanceof ISideConfiguration) {
        ISideConfiguration config = (ISideConfiguration) tile;
        // The read methods validate that data is stored
        config.getConfig().read(ItemDataUtils.getDataMap(stack));
        config.getEjector().read(ItemDataUtils.getDataMap(stack));
    }
    for (SubstanceType type : EnumUtils.SUBSTANCES) {
        if (type.canHandle(tile)) {
            DataHandlerUtils.readContainers(type.getContainers(tile), ItemDataUtils.getList(stack, type.getContainerTag()));
        }
    }
    if (tile instanceof ISustainedData && stack.hasTag()) {
        ((ISustainedData) tile).readSustainedData(stack);
    }
    if (tile.supportsRedstone() && ItemDataUtils.hasData(stack, NBTConstants.CONTROL_TYPE, NBT.TAG_INT)) {
        tile.setControlType(RedstoneControl.byIndexStatic(ItemDataUtils.getInt(stack, NBTConstants.CONTROL_TYPE)));
    }
    if (item instanceof ISustainedInventory && tile.persistInventory()) {
        tile.setInventory(((ISustainedInventory) item).getInventory(stack));
    }
}
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) TileEntitySecurityDesk(mekanism.common.tile.TileEntitySecurityDesk) UUID(java.util.UUID) ISustainedData(mekanism.common.tile.interfaces.ISustainedData) PacketSecurityUpdate(mekanism.common.network.to_client.PacketSecurityUpdate) ISideConfiguration(mekanism.common.tile.interfaces.ISideConfiguration)

Aggregations

UUID (java.util.UUID)1 ISecurityItem (mekanism.common.lib.security.ISecurityItem)1 PacketSecurityUpdate (mekanism.common.network.to_client.PacketSecurityUpdate)1 TileEntitySecurityDesk (mekanism.common.tile.TileEntitySecurityDesk)1 SubstanceType (mekanism.common.tile.base.SubstanceType)1 TileEntityMekanism (mekanism.common.tile.base.TileEntityMekanism)1 ISideConfiguration (mekanism.common.tile.interfaces.ISideConfiguration)1 ISustainedData (mekanism.common.tile.interfaces.ISustainedData)1 ISustainedInventory (mekanism.common.tile.interfaces.ISustainedInventory)1 Item (net.minecraft.item.Item)1