use of mekanism.common.tile.TileEntityChemicalTank 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;
}
Aggregations