Skip to content

Commit

Permalink
Inject waterloggable hoppers into the original TE's valid block set
Browse files Browse the repository at this point in the history
This seems the best course of action, ensures it's got the right
datafixers, and leaves non-waterlogged hoppers with vanilla save data.
  • Loading branch information
TeamSpen210 committed Dec 24, 2019
1 parent ae6d51f commit 89f947b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
@@ -1,5 +1,6 @@
package knightminer.inspirations.tweaks;

import com.google.common.collect.ImmutableSet;
import knightminer.inspirations.common.Config;
import knightminer.inspirations.common.PulseBase;
import knightminer.inspirations.common.item.HidableItem;
Expand All @@ -22,10 +23,12 @@
import net.minecraft.item.Food;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.Items;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.potion.Potions;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
Expand Down Expand Up @@ -144,6 +147,20 @@ public void registerItem(Register<Item> event) {
// ), "silverfish_powder");
}

@SubscribeEvent
public void registerTileEntities(Register<TileEntityType<?>> event) {
if (Config.waterlogHopper.get()) {
// We need to inject our replacement hopper blocks into the valid ones for the TE type.
// It's an immutable set, so we need to replace it entirely.
// TODO: This isn't thread-safe with any other mods doing the same!
TileEntityType.HOPPER.validBlocks = new ImmutableSet.Builder<Block>()

This comment has been minimized.

Copy link
@KnightMiner

KnightMiner Dec 25, 2019

Owner

There is a Forge PR adding a more proper way to do this. Otherwise, can we use a synchronized block and encourage other mods to do the same?

.addAll(TileEntityType.HOPPER.validBlocks)
.add(dryHopper)
.add(wetHopper)
.build();
}
}

@SubscribeEvent
public void setup(FMLCommonSetupEvent event) {
// TODO: Forge needs to implement the ability to inject these into the loot tables.
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/META-INF/accesstransformer.cfg
Expand Up @@ -23,4 +23,7 @@ public net.minecraft.tileentity.LockableTileEntity field_174901_a # code
public net.minecraft.world.LockCode field_180161_b # lock

# Portal color
public net.minecraft.client.renderer.chunk.ChunkRenderCache field_212408_i # world
public net.minecraft.client.renderer.chunk.ChunkRenderCache field_212408_i # world

# Hopper waterlogging - inject new blocks into TE
public-f net.minecraft.tileentity.TileEntityType field_223046_I # validBlocks

0 comments on commit 89f947b

Please sign in to comment.