Skip to content

Commit f31c31e

Browse files
committed
New Rule: chestBoatDupeFix
1 parent 7db23b2 commit f31c31e

File tree

5 files changed

+116
-0
lines changed

5 files changed

+116
-0
lines changed

src/main/java/carpetfixes/CFSettings.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,6 +1871,13 @@ other bugs, except they deserve a category of their own (for sorting purposes...
18711871
)
18721872
public static boolean horseDupeFix = false;
18731873

1874+
//by FX - PR0CESS
1875+
@Rule(
1876+
desc = "Fixes MULTIPLE dupes using chest boats",
1877+
category = {BUGFIX,DUPE}
1878+
)
1879+
public static boolean chestBoatDupeFix = false;
1880+
18741881

18751882
/*
18761883
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package carpetfixes.mixins.dupeFixes.chestBoatDupe;
2+
3+
import carpetfixes.CFSettings;
4+
import carpetfixes.patches.linkedEntityInventory;
5+
import net.minecraft.entity.Entity;
6+
import net.minecraft.entity.player.PlayerInventory;
7+
import net.minecraft.entity.vehicle.ChestBoatEntity;
8+
import net.minecraft.inventory.Inventory;
9+
import net.minecraft.screen.GenericContainerScreenHandler;
10+
import org.spongepowered.asm.mixin.Mixin;
11+
import org.spongepowered.asm.mixin.injection.At;
12+
import org.spongepowered.asm.mixin.injection.Redirect;
13+
14+
@Mixin(ChestBoatEntity.class)
15+
public class ChestBoatEntity_screenDupeMixin {
16+
17+
private final Entity self = (Entity)(Object)this;
18+
19+
20+
@Redirect(
21+
method = "createMenu",
22+
at = @At(
23+
value = "INVOKE",
24+
target = "Lnet/minecraft/screen/GenericContainerScreenHandler;createGeneric9x3(" +
25+
"ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/inventory/Inventory;)" +
26+
"Lnet/minecraft/screen/GenericContainerScreenHandler;"
27+
)
28+
)
29+
public GenericContainerScreenHandler createMenu(int syncId, PlayerInventory playerInventory, Inventory inventory) {
30+
if (CFSettings.chestBoatDupeFix) {
31+
GenericContainerScreenHandler screenHandler = GenericContainerScreenHandler.createGeneric9x3(
32+
syncId, playerInventory, inventory
33+
);
34+
((linkedEntityInventory)screenHandler).setLinkedEntity(self);
35+
return screenHandler;
36+
} else {
37+
return GenericContainerScreenHandler.createGeneric9x3(syncId, playerInventory, inventory);
38+
}
39+
}
40+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package carpetfixes.mixins.dupeFixes.chestBoatDupe;
2+
3+
import carpetfixes.CFSettings;
4+
import carpetfixes.patches.linkedEntityInventory;
5+
import net.minecraft.entity.Entity;
6+
import net.minecraft.entity.player.PlayerEntity;
7+
import net.minecraft.entity.vehicle.VehicleInventory;
8+
import net.minecraft.inventory.Inventory;
9+
import net.minecraft.item.ItemStack;
10+
import net.minecraft.screen.GenericContainerScreenHandler;
11+
import org.jetbrains.annotations.Nullable;
12+
import org.spongepowered.asm.mixin.Final;
13+
import org.spongepowered.asm.mixin.Mixin;
14+
import org.spongepowered.asm.mixin.Shadow;
15+
import org.spongepowered.asm.mixin.injection.At;
16+
import org.spongepowered.asm.mixin.injection.Inject;
17+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
18+
19+
@Mixin(GenericContainerScreenHandler.class)
20+
public class GenericContainerScreenHandler_dupeMixin implements linkedEntityInventory {
21+
22+
@Shadow
23+
@Final
24+
private Inventory inventory;
25+
26+
@Nullable
27+
private Entity linkedEntity;
28+
29+
@Override
30+
public void setLinkedEntity(@Nullable Entity linkedEntity) {
31+
this.linkedEntity = linkedEntity;
32+
}
33+
34+
35+
@Inject(
36+
method = "canUse",
37+
at = @At("HEAD"),
38+
cancellable = true
39+
)
40+
public void canUseWithEntity(PlayerEntity player, CallbackInfoReturnable<Boolean> cir) {
41+
if (CFSettings.chestBoatDupeFix && this.linkedEntity != null) {
42+
boolean isValid = true;
43+
if (this.linkedEntity instanceof VehicleInventory vehicleInventory)
44+
isValid = vehicleInventory.canPlayerAccess(player);
45+
cir.setReturnValue(isValid && this.inventory.canPlayerUse(player) && this.linkedEntity.isAlive());
46+
}
47+
}
48+
49+
50+
@Inject(
51+
method = "transferSlot(Lnet/minecraft/entity/player/PlayerEntity;I)Lnet/minecraft/item/ItemStack;",
52+
at = @At("HEAD"),
53+
cancellable = true
54+
)
55+
private void onlyTransferIfEntityAlive(PlayerEntity p, int i, CallbackInfoReturnable<ItemStack> cir) {
56+
if (CFSettings.chestBoatDupeFix && this.linkedEntity != null &&
57+
(p.isDead() || p.isRemoved() || !this.linkedEntity.isAlive() || this.linkedEntity.isRemoved()))
58+
cir.setReturnValue(ItemStack.EMPTY);
59+
}
60+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package carpetfixes.patches;
2+
3+
import net.minecraft.entity.Entity;
4+
5+
public interface linkedEntityInventory {
6+
void setLinkedEntity(Entity linkedEntity);
7+
}

src/main/resources/carpet-fixes.mixins.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@
141141
"dupeFixes.SimpleInventory_dataDupeMixin",
142142
"dupeFixes.TripwireBlock_stringDupeMixin",
143143
"dupeFixes.TripwireHookBlock_hookDupeMixin",
144+
"dupeFixes.chestBoatDupe.ChestBoatEntity_screenDupeMixin",
145+
"dupeFixes.chestBoatDupe.GenericContainerScreenHandler_dupeMixin",
144146
"dupeFixes.saferItemTransfer.DropperBlock_dontCopyMixin",
145147
"entityFixes.AbstractDecorationEntity_triggersTrapsMixin",
146148
"entityFixes.AbstractMinecartEntity_armorStandMixin",

0 commit comments

Comments
 (0)