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));
}
}
Aggregations