hopper counters
This commit is contained in:
1 parent
9cf9928bbd
commit
4582317cce
2 files changed
+62
-1
No files matched your search
@@ -0,0 +1,60 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import net.minecraft.block.HopperBlock;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.block.entity.HopperBlockEntity;
|
||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.DyeColor;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import carpet.helpers.HopperCounter;
|
||||
import carpet.utils.WoolTool;
|
||||
|
||||
@Mixin(HopperBlockEntity.class)
|
||||
public abstract class HopperBlockEntityMixin extends LootableContainerBlockEntity {
|
||||
|
||||
protected HopperBlockEntityMixin(BlockEntityType<?> blockEntityType_1) {
|
||||
super(blockEntityType_1);
|
||||
}
|
||||
|
||||
@Shadow
|
||||
public abstract double getHopperX();
|
||||
|
||||
@Shadow
|
||||
public abstract double getHopperY();
|
||||
|
||||
@Shadow
|
||||
public abstract double getHopperZ();
|
||||
|
||||
@Shadow
|
||||
public abstract void setInvStack(int int_1, ItemStack itemStack_1);
|
||||
|
||||
@Shadow
|
||||
public abstract int getInvSize();
|
||||
|
||||
@Inject(method = "insert", at = @At("HEAD"), cancellable = true)
|
||||
private void onInsert(CallbackInfoReturnable<Boolean> cir)
|
||||
{
|
||||
if (CarpetSettings.b_hopperCounters) {
|
||||
DyeColor wool_color = WoolTool.getWoolColorAtPosition(
|
||||
getWorld(),
|
||||
new BlockPos(getHopperX(), getHopperY(), getHopperZ()).offset(this.getCachedState().get(HopperBlock.FACING)));
|
||||
if (wool_color != null) {
|
||||
for (int i = 0; i < this.getInvSize(); ++i) {
|
||||
if (!this.getInvStack(i).isEmpty()) {
|
||||
ItemStack itemstack = this.getInvStack(i);//.copy();
|
||||
HopperCounter.COUNTERS.get(wool_color).add(this.getWorld().getServer(), itemstack);
|
||||
this.setInvStack(i, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
cir.setReturnValue(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user