Skip to content

Commit

Permalink
Fix gauge droppers not exposing capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
pupnewfster committed Feb 24, 2024
1 parent 401f215 commit de3a1de
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,39 +87,31 @@ private ItemRegistryObject<ITEM> addContainerCapability(ContainerType<?, ?, ?> c
}

@Internal
public <TANK extends MergedChemicalTank> ItemRegistryObject<ITEM> addMissingMergedAttachments(Supplier<AttachmentType<TANK>> backingAttachment, boolean supportsFluid) {
return addMissingMergedTanks(backingAttachment, supportsFluid, containerType -> {
});
}

@Internal
public <TANK extends MergedChemicalTank> ItemRegistryObject<ITEM> addMissingMergedCapabilityTanks(Supplier<AttachmentType<TANK>> backingAttachment, boolean supportsFluid) {
return addMissingMergedTanks(backingAttachment, supportsFluid, this::addContainerCapability);
}

private <TANK extends MergedChemicalTank> ItemRegistryObject<ITEM> addMissingMergedTanks(Supplier<AttachmentType<TANK>> backingAttachment, boolean supportsFluid,
Consumer<ContainerType<?, ?, ?>> onAdded) {
int added = addMissingTankType(ContainerType.GAS, onAdded, stack -> stack.getData(backingAttachment).getGasTank());
added += addMissingTankType(ContainerType.INFUSION, onAdded, stack -> stack.getData(backingAttachment).getInfusionTank());
added += addMissingTankType(ContainerType.PIGMENT, onAdded, stack -> stack.getData(backingAttachment).getPigmentTank());
added += addMissingTankType(ContainerType.SLURRY, onAdded, stack -> stack.getData(backingAttachment).getSlurryTank());
public <TANK extends MergedChemicalTank> ItemRegistryObject<ITEM> addMissingMergedTanks(Supplier<AttachmentType<TANK>> backingAttachment, boolean supportsFluid,
boolean exposeCapability) {
int added = addMissingTankType(ContainerType.GAS, exposeCapability, stack -> stack.getData(backingAttachment).getGasTank());
added += addMissingTankType(ContainerType.INFUSION, exposeCapability, stack -> stack.getData(backingAttachment).getInfusionTank());
added += addMissingTankType(ContainerType.PIGMENT, exposeCapability, stack -> stack.getData(backingAttachment).getPigmentTank());
added += addMissingTankType(ContainerType.SLURRY, exposeCapability, stack -> stack.getData(backingAttachment).getSlurryTank());
if (supportsFluid) {
Supplier<AttachmentType<MergedTank>> attachment = (Supplier) backingAttachment;
added += addMissingTankType(ContainerType.FLUID, onAdded, stack -> stack.getData(attachment).getFluidTank());
added += addMissingTankType(ContainerType.FLUID, exposeCapability, stack -> stack.getData(attachment).getFluidTank());
}
if (added == 0) {
throw new IllegalStateException("Unnecessary addMissingMergedAttachments call");
throw new IllegalStateException("Unnecessary addMissingMergedTanks call");
}
return this;
}

private <CONTAINER extends INBTSerializable<CompoundTag>> int addMissingTankType(ContainerType<CONTAINER, ?, ?> containerType, Consumer<ContainerType<?, ?, ?>> onAdded,
private <CONTAINER extends INBTSerializable<CompoundTag>> int addMissingTankType(ContainerType<CONTAINER, ?, ?> containerType, boolean exposeCapability,
Function<ItemStack, CONTAINER> defaultCreator) {
if (defaultContainers != null && defaultContainers.containsKey(containerType)) {
return 0;
}
addAttachmentOnlyContainer(containerType, defaultCreator);
onAdded.accept(containerType);
if (exposeCapability) {
addContainerCapability(containerType);
}
return 1;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/mekanism/common/registries/MekanismBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ private MekanismBlocks() {
gas -> MekanismRecipeType.DISSOLUTION.getInputCache().containsInputB(null, gas.getStack(1))
),
stack.getData(MekanismAttachmentTypes.CDC_CONTENTS_HANDLER).getGasTank()
)).addMissingMergedAttachments(MekanismAttachmentTypes.CDC_CONTENTS_HANDLER, false)
)).addMissingMergedTanks(MekanismAttachmentTypes.CDC_CONTENTS_HANDLER, false, false)
.addAttachmentOnlyContainers(ContainerType.ITEM, stack -> ItemSlotsBuilder.builder(stack)
.addGasSlotWithConversion(0)
.addInput(MekanismRecipeType.DISSOLUTION, ItemChemical::containsInputA)
Expand Down Expand Up @@ -538,7 +538,7 @@ private MekanismBlocks() {
public static final BlockRegistryObject<BlockTileModel<TileEntityChemicalCrystallizer, Machine<TileEntityChemicalCrystallizer>>, ItemBlockTooltip<BlockTileModel<TileEntityChemicalCrystallizer, Machine<TileEntityChemicalCrystallizer>>>> CHEMICAL_CRYSTALLIZER =
BLOCKS.register("chemical_crystallizer", () -> new BlockTileModel<>(MekanismBlockTypes.CHEMICAL_CRYSTALLIZER, properties -> properties.mapColor(BlockResourceInfo.STEEL.getMapColor())), ItemBlockTooltip::new)
.forItemHolder(holder -> holder
.addMissingMergedAttachments(MekanismAttachmentTypes.CRYSTALLIZER_CONTENTS_HANDLER, false)
.addMissingMergedTanks(MekanismAttachmentTypes.CRYSTALLIZER_CONTENTS_HANDLER, false, false)
.addAttachmentOnlyContainers(ContainerType.ITEM, stack -> ItemSlotsBuilder.builder(stack)
.addContainerSlot(stack.getData(MekanismAttachmentTypes.CRYSTALLIZER_CONTENTS_HANDLER), MergedChemicalInventorySlot::fill)
.addOutput()
Expand Down Expand Up @@ -885,7 +885,7 @@ private static BlockRegistryObject<BlockTileModel<TileEntityChemicalTank, Machin
Machine<TileEntityChemicalTank> type) {
return registerTieredBlock(type, "_chemical_tank", color -> new BlockTileModel<>(type, properties -> properties.mapColor(color)), ItemBlockChemicalTank::new)
.forItemHolder(holder -> holder
.addMissingMergedCapabilityTanks(MekanismAttachmentTypes.CHEMICAL_TANK_CONTENTS_HANDLER, false)
.addMissingMergedTanks(MekanismAttachmentTypes.CHEMICAL_TANK_CONTENTS_HANDLER, false, true)
.addAttachmentOnlyContainers(ContainerType.ITEM, stack -> {
MergedChemicalTank tank = stack.getData(MekanismAttachmentTypes.CHEMICAL_TANK_CONTENTS_HANDLER);
return ItemSlotsBuilder.builder(stack)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private MekanismItems() {
public static final ItemRegistryObject<ItemCraftingFormula> CRAFTING_FORMULA = ITEMS.registerItem("crafting_formula", ItemCraftingFormula::new);
public static final ItemRegistryObject<ItemSeismicReader> SEISMIC_READER = ITEMS.registerItem("seismic_reader", ItemSeismicReader::new);
public static final ItemRegistryObject<ItemGaugeDropper> GAUGE_DROPPER = ITEMS.registerItem("gauge_dropper", ItemGaugeDropper::new)
.addMissingMergedAttachments(MekanismAttachmentTypes.GAUGE_DROPPER_CONTENTS_HANDLER, true);
.addMissingMergedTanks(MekanismAttachmentTypes.GAUGE_DROPPER_CONTENTS_HANDLER, true, true);
public static final ItemRegistryObject<ItemGeigerCounter> GEIGER_COUNTER = ITEMS.registerItem("geiger_counter", ItemGeigerCounter::new);
public static final ItemRegistryObject<ItemDosimeter> DOSIMETER = ITEMS.registerItem("dosimeter", ItemDosimeter::new);
public static final ItemRegistryObject<ItemCanteen> CANTEEN = ITEMS.registerItem("canteen", ItemCanteen::new)
Expand Down

0 comments on commit de3a1de

Please sign in to comment.