mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Fixed mimics rolling multiple times
This commit is contained in:
parent
715519e1f1
commit
648f1838e7
1 changed files with 17 additions and 9 deletions
|
@ -10,6 +10,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.entity.mob.MimicEntity;
|
import com.minelittlepony.unicopia.entity.mob.MimicEntity;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.util.TriState;
|
||||||
import net.minecraft.block.entity.LockableContainerBlockEntity;
|
import net.minecraft.block.entity.LockableContainerBlockEntity;
|
||||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
@ -22,7 +23,7 @@ import net.minecraft.util.Identifier;
|
||||||
abstract class MixinLootableContainerBlockEntity extends LockableContainerBlockEntity implements MimicEntity.MimicGeneratable {
|
abstract class MixinLootableContainerBlockEntity extends LockableContainerBlockEntity implements MimicEntity.MimicGeneratable {
|
||||||
private Identifier mimicLootTable;
|
private Identifier mimicLootTable;
|
||||||
private boolean allowMimics = true;
|
private boolean allowMimics = true;
|
||||||
private boolean isMimic;
|
private TriState isMimic = TriState.DEFAULT;
|
||||||
|
|
||||||
@Shadow
|
@Shadow
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -32,24 +33,25 @@ abstract class MixinLootableContainerBlockEntity extends LockableContainerBlockE
|
||||||
|
|
||||||
@Inject(method = "deserializeLootTable", at = @At("HEAD"))
|
@Inject(method = "deserializeLootTable", at = @At("HEAD"))
|
||||||
private void deserializeMimic(NbtCompound nbt, CallbackInfoReturnable<Boolean> info) {
|
private void deserializeMimic(NbtCompound nbt, CallbackInfoReturnable<Boolean> info) {
|
||||||
isMimic = nbt.getBoolean("mimic");
|
isMimic = nbt.contains("mimic") ? TriState.of(nbt.getBoolean("mimic")) : TriState.DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "serializeLootTable", at = @At("HEAD"))
|
@Inject(method = "serializeLootTable", at = @At("HEAD"))
|
||||||
private void serializeMimic(NbtCompound nbt, CallbackInfoReturnable<Boolean> info) {
|
private void serializeMimic(NbtCompound nbt, CallbackInfoReturnable<Boolean> info) {
|
||||||
nbt.putBoolean("mimic", isMimic);
|
if (isMimic != TriState.DEFAULT) {
|
||||||
|
nbt.putBoolean("mimic", isMimic.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAllowMimics(boolean allowMimics) {
|
public void setAllowMimics(boolean allowMimics) {
|
||||||
this.allowMimics = allowMimics;
|
this.allowMimics = allowMimics;
|
||||||
this.isMimic &= allowMimics;
|
|
||||||
markDirty();
|
markDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMimic(boolean mimic) {
|
public void setMimic(boolean mimic) {
|
||||||
isMimic = mimic;
|
isMimic = TriState.of(mimic);
|
||||||
markDirty();
|
markDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,11 +70,17 @@ abstract class MixinLootableContainerBlockEntity extends LockableContainerBlockE
|
||||||
shift = Shift.AFTER
|
shift = Shift.AFTER
|
||||||
), cancellable = true)
|
), cancellable = true)
|
||||||
private void onCreateMenu(int syncId, PlayerInventory playerInventory, PlayerEntity player, CallbackInfoReturnable<ScreenHandler> info) {
|
private void onCreateMenu(int syncId, PlayerInventory playerInventory, PlayerEntity player, CallbackInfoReturnable<ScreenHandler> info) {
|
||||||
if (player != null && (isMimic || (allowMimics && MimicEntity.shouldConvert(player.getWorld(), getPos(), player, mimicLootTable)))) {
|
if (player != null && allowMimics) {
|
||||||
|
if (isMimic == TriState.DEFAULT) {
|
||||||
|
isMimic = TriState.of(MimicEntity.shouldConvert(player.getWorld(), getPos(), player, mimicLootTable));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isMimic.get()) {
|
||||||
var mimic = MimicEntity.spawnFromChest(player.getWorld(), getPos());
|
var mimic = MimicEntity.spawnFromChest(player.getWorld(), getPos());
|
||||||
if (mimic != null) {
|
if (mimic != null) {
|
||||||
info.setReturnValue(mimic.createScreenHandler(syncId, playerInventory, player));
|
info.setReturnValue(mimic.createScreenHandler(syncId, playerInventory, player));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
mimicLootTable = null;
|
mimicLootTable = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue