-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix hoppers not working correctly with water purifiers on Forge
- Loading branch information
Showing
2 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
forge/src/main/java/toughasnails/forge/mixin/MixinWaterPurifierBlockEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/******************************************************************************* | ||
* Copyright 2023, the Glitchfiend Team. | ||
* All rights reserved. | ||
******************************************************************************/ | ||
package toughasnails.forge.mixin; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.world.WorldlyContainer; | ||
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraftforge.common.capabilities.Capability; | ||
import net.minecraftforge.common.capabilities.ForgeCapabilities; | ||
import net.minecraftforge.common.util.LazyOptional; | ||
import net.minecraftforge.items.IItemHandler; | ||
import net.minecraftforge.items.wrapper.SidedInvWrapper; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import toughasnails.block.entity.WaterPurifierBlockEntity; | ||
|
||
@Mixin(value = WaterPurifierBlockEntity.class, remap = false) | ||
public abstract class MixinWaterPurifierBlockEntity extends BaseContainerBlockEntity implements WorldlyContainer { | ||
protected MixinWaterPurifierBlockEntity(BlockEntityType<?> p_155076_, BlockPos p_155077_, BlockState p_155078_) { | ||
super(p_155076_, p_155077_, p_155078_); | ||
} | ||
|
||
@Unique | ||
LazyOptional<? extends IItemHandler>[] handlers; | ||
|
||
@Inject(method="<init>", at=@At("RETURN")) | ||
public void onConstructed(BlockPos pos, BlockState state, CallbackInfo ci) | ||
{ | ||
this.handlers = SidedInvWrapper.create(this, Direction.UP, Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST); | ||
} | ||
|
||
@Override | ||
public <T> LazyOptional<T> getCapability(Capability<T> capability, @Nullable Direction facing) | ||
{ | ||
if (!this.remove && facing != null && capability == ForgeCapabilities.ITEM_HANDLER) { | ||
if (facing == Direction.UP) | ||
return handlers[0].cast(); | ||
else if (facing == Direction.DOWN) | ||
return handlers[1].cast(); | ||
else | ||
return handlers[2].cast(); | ||
} | ||
return super.getCapability(capability, facing); | ||
} | ||
|
||
@Override | ||
public void invalidateCaps() | ||
{ | ||
super.invalidateCaps(); | ||
for (int x = 0; x < handlers.length; x++) | ||
handlers[x].invalidate(); | ||
} | ||
|
||
@Override | ||
public void reviveCaps() | ||
{ | ||
super.reviveCaps(); | ||
this.handlers = SidedInvWrapper.create(this, Direction.UP, Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters