Skip to content

Commit

Permalink
Fix hoppers not working correctly with water purifiers on Forge
Browse files Browse the repository at this point in the history
  • Loading branch information
Adubbz committed Jan 6, 2024
1 parent 4a43a8c commit e6013a9
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
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);
}
}
3 changes: 2 additions & 1 deletion forge/src/main/resources/toughasnails.forge.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"compatibilityLevel": "JAVA_17",
"refmap": "toughasnails.refmap.json",
"mixins": [
"MixinTemperatureHelperImpl"
"MixinTemperatureHelperImpl",
"MixinWaterPurifierBlockEntity"
],
"client": [
"client.MixinGui"
Expand Down

0 comments on commit e6013a9

Please sign in to comment.