use of mekanism.common.lib.frequency.IFrequencyHandler in project Mekanism by mekanism.
the class BaseBlockLootTables method dropSelfWithContents.
protected void dropSelfWithContents(List<IBlockProvider> blockProviders) {
// For example, when writing this we added dump mode for chemical tanks to getting transferred to the item
for (IBlockProvider blockProvider : blockProviders) {
Block block = blockProvider.getBlock();
if (skipBlock(block)) {
continue;
}
CopyNbt.Builder nbtBuilder = CopyNbt.copyData(Source.BLOCK_ENTITY);
boolean hasData = false;
boolean hasContents = false;
@Nullable TileEntity tile = null;
if (block instanceof IHasTileEntity) {
tile = ((IHasTileEntity<?>) block).getTileType().create();
}
if (tile instanceof IFrequencyHandler && ((IFrequencyHandler) tile).getFrequencyComponent().hasCustomFrequencies()) {
nbtBuilder.copy(NBTConstants.COMPONENT_FREQUENCY, NBTConstants.MEK_DATA + "." + NBTConstants.COMPONENT_FREQUENCY);
hasData = true;
}
if (Attribute.has(block, AttributeSecurity.class)) {
// TODO: Should we just save the entire security component?
nbtBuilder.copy(NBTConstants.COMPONENT_SECURITY + "." + NBTConstants.OWNER_UUID, NBTConstants.MEK_DATA + "." + NBTConstants.OWNER_UUID);
nbtBuilder.copy(NBTConstants.COMPONENT_SECURITY + "." + NBTConstants.SECURITY_MODE, NBTConstants.MEK_DATA + "." + NBTConstants.SECURITY_MODE);
hasData = true;
}
if (Attribute.has(block, AttributeUpgradeSupport.class)) {
nbtBuilder.copy(NBTConstants.COMPONENT_UPGRADE, NBTConstants.MEK_DATA + "." + NBTConstants.COMPONENT_UPGRADE);
hasData = true;
}
if (tile instanceof ISideConfiguration) {
nbtBuilder.copy(NBTConstants.COMPONENT_CONFIG, NBTConstants.MEK_DATA + "." + NBTConstants.COMPONENT_CONFIG);
nbtBuilder.copy(NBTConstants.COMPONENT_EJECTOR, NBTConstants.MEK_DATA + "." + NBTConstants.COMPONENT_EJECTOR);
hasData = true;
}
if (tile instanceof ISustainedData) {
Set<Entry<String, String>> remapEntries = ((ISustainedData) tile).getTileDataRemap().entrySet();
for (Entry<String, String> remapEntry : remapEntries) {
nbtBuilder.copy(remapEntry.getKey(), NBTConstants.MEK_DATA + "." + remapEntry.getValue());
}
if (!remapEntries.isEmpty()) {
hasData = true;
}
}
if (Attribute.has(block, AttributeRedstone.class)) {
nbtBuilder.copy(NBTConstants.CONTROL_TYPE, NBTConstants.MEK_DATA + "." + NBTConstants.CONTROL_TYPE);
hasData = true;
}
if (tile instanceof TileEntityMekanism) {
TileEntityMekanism tileEntity = (TileEntityMekanism) tile;
for (SubstanceType type : EnumUtils.SUBSTANCES) {
if (tileEntity.handles(type) && !type.getContainers(tileEntity).isEmpty()) {
nbtBuilder.copy(type.getContainerTag(), NBTConstants.MEK_DATA + "." + type.getContainerTag());
hasData = true;
if (type != SubstanceType.ENERGY && type != SubstanceType.HEAT) {
hasContents = true;
}
}
}
}
if (Attribute.has(block, AttributeInventory.class)) {
// then only copy the slots if we actually have any slots because otherwise maybe something just went wrong
if (!(tile instanceof IItemHandler) || ((IItemHandler) tile).getSlots() > 0) {
// If we don't actually handle saving an inventory (such as the quantum entangloporter, don't actually add it as something to copy)
if (!(tile instanceof TileEntityMekanism) || ((TileEntityMekanism) tile).persistInventory()) {
nbtBuilder.copy(NBTConstants.ITEMS, NBTConstants.MEK_DATA + "." + NBTConstants.ITEMS);
hasData = true;
hasContents = true;
}
}
}
if (block instanceof BlockCardboardBox) {
// TODO: Do this better so that it doesn't have to be as hard coded to being a cardboard box
nbtBuilder.copy(NBTConstants.DATA, NBTConstants.MEK_DATA + "." + NBTConstants.DATA);
hasData = true;
}
if (!hasData) {
// To keep the json as clean as possible don't bother even registering a blank accept function if we have no
// persistent data that we want to copy. Also log a warning so that we don't have to attempt to check against
// that block
dropSelf(block);
} else {
add(block, LootTable.lootTable().withPool(applyExplosionCondition(hasContents, LootPool.lootPool().name("main").setRolls(ConstantRange.exactly(1)).add(ItemLootEntry.lootTableItem(block).apply(nbtBuilder)))));
}
}
}
use of mekanism.common.lib.frequency.IFrequencyHandler in project Mekanism by mekanism.
the class PacketGuiSetFrequency method handle.
@Override
public void handle(NetworkEvent.Context context) {
ServerPlayerEntity player = context.getSender();
if (player == null) {
return;
}
if (updateType.isTile()) {
TileEntity tile = WorldUtils.getTileEntity(player.level, tilePosition);
if (SecurityUtils.canAccess(player, tile) && tile instanceof IFrequencyHandler) {
if (updateType == FrequencyUpdate.SET_TILE) {
((IFrequencyHandler) tile).setFrequency(type, data, player.getUUID());
} else if (updateType == FrequencyUpdate.REMOVE_TILE) {
((IFrequencyHandler) tile).removeFrequency(type, data, player.getUUID());
}
}
} else {
ItemStack stack = player.getItemInHand(currentHand);
if (SecurityUtils.canAccess(player, stack) && stack.getItem() instanceof IFrequencyItem) {
IFrequencyItem item = (IFrequencyItem) stack.getItem();
FrequencyManager<FREQ> manager = type.getManager(data, player.getUUID());
if (updateType == FrequencyUpdate.SET_ITEM) {
// Note: We don't bother validating if the frequency is public or not here, as if it isn't then
// a new private frequency will just be created for the player who sent a packet they shouldn't
// have been able to send due to not knowing what private frequencies exist for other players
item.setFrequency(stack, manager.getOrCreateFrequency(data, player.getUUID()));
} else if (updateType == FrequencyUpdate.REMOVE_ITEM) {
if (manager.remove(data.getKey(), player.getUUID())) {
FrequencyIdentity current = item.getFrequencyIdentity(stack);
if (current != null && current.equals(data)) {
// If the frequency we are removing matches the stored frequency set it to nothing
item.setFrequency(stack, null);
}
}
}
}
}
}
Aggregations