Updated some Mixins

This commit is contained in:
Frank 2023-12-18 16:57:56 +01:00
parent 9fac62238a
commit f274de6f6f
17 changed files with 59 additions and 121 deletions

View file

@ -10,11 +10,11 @@ public class BaseBoatItem extends BoatItem implements CustomBoatTypeOverride, It
public BaseBoatItem(boolean bl, BoatTypeOverride type, Properties properties) {
super(bl, Boat.Type.OAK, properties);
setCustomType(type);
bcl_setCustomType(type);
}
@Override
public void setCustomType(BoatTypeOverride type) {
public void bcl_setCustomType(BoatTypeOverride type) {
customType = type;
}

View file

@ -1,6 +1,6 @@
package org.betterx.bclib.items.boat;
public interface CustomBoatTypeOverride {
void setCustomType(BoatTypeOverride type);
void bcl_setCustomType(BoatTypeOverride type);
BoatTypeOverride bcl_getCustomType();
}

View file

@ -34,7 +34,8 @@ public class AnvilScreenMixin extends ItemCombinerScreen<AnvilMenu> {
@Shadow
@Final
private static ResourceLocation ANVIL_LOCATION;
private final List<AbstractWidget> be_buttons = Lists.newArrayList();
@Unique
private final List<AbstractWidget> bcl_buttons = Lists.newArrayList();
public AnvilScreenMixin(AnvilMenu handler, Inventory playerInventory, Component title, ResourceLocation texture) {
super(handler, playerInventory, title, texture);
@ -47,6 +48,7 @@ public class AnvilScreenMixin extends ItemCombinerScreen<AnvilMenu> {
}
}
@Unique
private boolean bcl_hasRecipeError() {
//TODO: 1.19.4 check error conditions
return false;
@ -56,15 +58,15 @@ public class AnvilScreenMixin extends ItemCombinerScreen<AnvilMenu> {
protected void be_subInit(CallbackInfo info) {
int x = (width - imageWidth) / 2;
int y = (height - imageHeight) / 2;
be_buttons.clear();
be_buttons.add(Button.builder(Component.literal("<"), b -> be_previousRecipe())
.bounds(x + 8, y + 45, 15, 20)
.build());
be_buttons.add(Button.builder(Component.literal(">"), b -> be_nextRecipe())
.bounds(x + 154, y + 45, 15, 20)
.build());
bcl_buttons.clear();
bcl_buttons.add(Button.builder(Component.literal("<"), b -> be_previousRecipe())
.bounds(x + 8, y + 45, 15, 20)
.build());
bcl_buttons.add(Button.builder(Component.literal(">"), b -> be_nextRecipe())
.bounds(x + 154, y + 45, 15, 20)
.build());
be_buttons.forEach(button -> addWidget(button));
bcl_buttons.forEach(this::addWidget);
}
@Inject(method = "renderFg", at = @At("TAIL"))
@ -75,9 +77,7 @@ public class AnvilScreenMixin extends ItemCombinerScreen<AnvilMenu> {
float delta,
CallbackInfo info
) {
be_buttons.forEach(button -> {
button.render(guiGraphics, mouseX, mouseY, delta);
});
bcl_buttons.forEach(button -> button.render(guiGraphics, mouseX, mouseY, delta));
}
@Inject(method = "slotChanged", at = @At("HEAD"), cancellable = true)
@ -85,21 +85,23 @@ public class AnvilScreenMixin extends ItemCombinerScreen<AnvilMenu> {
AnvilScreenHandlerExtended anvilHandler = (AnvilScreenHandlerExtended) handler;
if (anvilHandler.bcl_getCurrentRecipe() != null) {
if (anvilHandler.bcl_getRecipes().size() > 1) {
be_buttons.forEach(button -> button.visible = true);
bcl_buttons.forEach(button -> button.visible = true);
} else {
be_buttons.forEach(button -> button.visible = false);
bcl_buttons.forEach(button -> button.visible = false);
}
name.setValue("");
info.cancel();
} else {
be_buttons.forEach(button -> button.visible = false);
bcl_buttons.forEach(button -> button.visible = false);
}
}
@Unique
private void be_nextRecipe() {
((AnvilScreenHandlerExtended) menu).be_nextRecipe();
}
@Unique
private void be_previousRecipe() {
((AnvilScreenHandlerExtended) menu).be_previousRecipe();
}
@ -109,10 +111,10 @@ public class AnvilScreenMixin extends ItemCombinerScreen<AnvilMenu> {
//@Override
public boolean bcl$mouseClicked(double mouseX, double mouseY, int button) {
if (minecraft != null) {
for (AbstractWidget elem : be_buttons) {
for (AbstractWidget elem : bcl_buttons) {
if (elem.visible && elem.mouseClicked(mouseX, mouseY, button)) {
if (minecraft.gameMode != null) {
int i = be_buttons.indexOf(elem);
int i = bcl_buttons.indexOf(elem);
minecraft.gameMode.handleInventoryButtonClick(menu.containerId, i);
return true;
}

View file

@ -54,7 +54,7 @@ public abstract class LevelRendererMixin implements LevelRendererAccess {
}
@Shadow
protected static void renderShape(
private static void renderShape(
PoseStack poseStack,
VertexConsumer vertexConsumer,
VoxelShape voxelShape,
@ -107,7 +107,7 @@ public abstract class LevelRendererMixin implements LevelRendererAccess {
final VertexConsumer consumer = bufferSource.getBuffer(RenderType.lines());
final Vec3 camPos = camera.getPosition();
this.renderShape(
renderShape(
poseStack, consumer,
state.getShape(minecraft.level, pos, CollisionContext.of(camera.getEntity())),
pos.getX() - camPos.x(), pos.getY() - camPos.y(), pos.getZ() - camPos.z(),

View file

@ -14,8 +14,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
public class AnvilBlockMixin {
@Inject(method = "damage", at = @At("HEAD"), cancellable = true)
private static void bclib_anvilDamage(BlockState state, CallbackInfoReturnable<BlockState> info) {
if (state.getBlock() instanceof BaseAnvilBlock) {
BaseAnvilBlock anvil = (BaseAnvilBlock) state.getBlock();
if (state.getBlock() instanceof BaseAnvilBlock anvil) {
info.setReturnValue(anvil.damageAnvilFall(state));
}
}

View file

@ -10,6 +10,7 @@ import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.structure.StructureSet;
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.ModifyArg;
@ -17,6 +18,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ChunkGenerator.class)
public class ChunkGeneratorMixin implements ChunkGeneratorAccessor {
@Unique
private int bclib_featureIteratorSeed;

View file

@ -18,8 +18,6 @@ public class DiggerItemMixin {
@Inject(method = "getDestroySpeed", at = @At(value = "RETURN"), cancellable = true)
void bn_getDestroySpeed(ItemStack stack, BlockState state, CallbackInfoReturnable<Float> cir) {
final Optional<Float> newSpeed = DiggerItemSpeed.getModifiedSpeed(stack, state, cir.getReturnValue());
if (newSpeed.isPresent()) {
cir.setReturnValue(newSpeed.get());
}
newSpeed.ifPresent(cir::setReturnValue);
}
}

View file

@ -1,64 +0,0 @@
package org.betterx.bclib.mixin.common;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.WritableRegistry;
import net.minecraft.world.level.dimension.DimensionType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(DimensionType.class)
public class DimensionTypeMixin {
// @Inject(
// method = "defaultDimensions(Lnet/minecraft/core/RegistryAccess;JZ)Lnet/minecraft/core/Registry;",
// locals = LocalCapture.CAPTURE_FAILHARD,
// at = @At("TAIL")
// )
private static void bclib_updateDimensions(
RegistryAccess registryAccess,
long seed,
boolean bl,
CallbackInfoReturnable<Registry> info,
WritableRegistry writableRegistry,
Registry registry,
Registry biomeRegistry,
Registry structureRegistry,
Registry noiseSettingsRegistry,
Registry noiseParamRegistry
) {
//This probably moved to WorldPresets.bootstrap();
// int id = writableRegistry.getId(writableRegistry.get(LevelStem.NETHER));
// writableRegistry.registerOrOverride(
// OptionalInt.of(id),
// LevelStem.NETHER,
// new LevelStem(
// registry.getOrCreateHolder(BuiltinDimensionTypes.NETHER),
// new NoiseBasedChunkGenerator(
// structureRegistry,
// noiseParamRegistry,
// new BCLibNetherBiomeSource(biomeRegistry, seed),
// seed,
// noiseSettingsRegistry.getOrCreateHolder(NoiseGeneratorSettings.NETHER))
// ),
// Lifecycle.stable()
// );
//
//
// id = writableRegistry.getId(writableRegistry.get(LevelStem.END));
// writableRegistry.registerOrOverride(
// OptionalInt.of(id),
// LevelStem.END,
// new LevelStem(
// registry.getOrCreateHolder(BuiltinDimensionTypes.END),
// new NoiseBasedChunkGenerator(
// structureRegistry,
// noiseParamRegistry,
// new BCLibEndBiomeSource(biomeRegistry, seed),
// seed,
// noiseSettingsRegistry.getOrCreateHolder(NoiseGeneratorSettings.END))
// ),
// Lifecycle.stable()
// );
}
}

View file

@ -2,8 +2,6 @@ package org.betterx.bclib.mixin.common;
import org.betterx.bclib.interfaces.LootPoolAccessor;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.LootPool;
import net.minecraft.world.level.storage.loot.entries.LootPoolEntryContainer;
import net.minecraft.world.level.storage.loot.functions.LootItemFunction;
@ -16,17 +14,9 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@Mixin(LootPool.class)
public class LootPoolMixin implements LootPoolAccessor {
@Shadow
@Final
private Predicate<LootParams> compositeCondition;
@Shadow
@Final
private BiFunction<ItemStack, LootParams, ItemStack> compositeFunction;
@Shadow
@Final
public NumberProvider rolls;
@ -34,11 +24,17 @@ public class LootPoolMixin implements LootPoolAccessor {
@Final
public NumberProvider bonusRolls;
@Shadow @Final public List<LootItemCondition> conditions;
@Shadow
@Final
public List<LootItemCondition> conditions;
@Shadow @Final public List<LootItemFunction> functions;
@Shadow
@Final
public List<LootItemFunction> functions;
@Shadow @Final public List<LootPoolEntryContainer> entries;
@Shadow
@Final
public List<LootPoolEntryContainer> entries;
@Override
public LootPool bcl_mergeEntries(List<LootPoolEntryContainer> newEntries) {

View file

@ -5,6 +5,7 @@ import net.minecraft.server.packs.resources.MultiPackResourceManager;
import net.minecraft.server.packs.resources.Resource;
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.CallbackInfoReturnable;
@ -13,6 +14,7 @@ import java.util.Optional;
@Mixin(MultiPackResourceManager.class)
public class MultiPackResourceManagerMixin {
@Unique
private static final String[] BCLIB_MISSING_RESOURCES = new String[]{
"dimension/the_end.json",
"dimension/the_nether.json",
@ -20,7 +22,7 @@ public class MultiPackResourceManagerMixin {
"dimension_type/the_nether.json"
};
@Inject(method = "getResource", at = @At("HEAD"), cancellable = true)
@Inject(method = "getResource", at = @At("HEAD"), cancellable = false)
private void bclib_hasResource(ResourceLocation resourceLocation, CallbackInfoReturnable<Optional<Resource>> info) {
if (resourceLocation.getNamespace().equals("minecraft")) {
for (String key : BCLIB_MISSING_RESOURCES) {

View file

@ -5,10 +5,13 @@ import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.levelgen.placement.PlacementContext;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
@Mixin(PlacementContext.class)
public class PlacementContextMixin implements org.betterx.bclib.interfaces.BCLPlacementContext {
@Unique
private Rotation bcl_rotation = Rotation.NONE;
@Unique
private Mirror bcl_mirror = Mirror.NONE;

View file

@ -9,6 +9,7 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.portal.PortalShape;
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.Redirect;
@ -44,6 +45,7 @@ public class PortalShapeMixin {
return be_FRAME(statePredicate, blockState, blockGetter, blockPos);
}
@Unique
private static boolean be_FRAME(StatePredicate FRAME, BlockState state, BlockGetter getter, BlockPos pos) {
return state.is(CommonBlockTags.NETHER_PORTAL_FRAME) || FRAME.test(state, getter, pos);
}

View file

@ -21,6 +21,7 @@ import net.minecraft.world.level.storage.ServerLevelData;
import net.minecraft.world.level.storage.WritableLevelData;
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;
@ -31,6 +32,7 @@ import java.util.function.Supplier;
@Mixin(ServerLevel.class)
public abstract class ServerLevelMixin extends Level {
@Unique
private static String bclib_lastWorld = null;
protected ServerLevelMixin(

View file

@ -15,7 +15,7 @@ public class BoatItemMixin {
Entity bcl_suse(Entity boat) {
if (this instanceof CustomBoatTypeOverride self) {
if (boat instanceof CustomBoatTypeOverride newBoat) {
newBoat.setCustomType(self.bcl_getCustomType());
newBoat.bcl_setCustomType(self.bcl_getCustomType());
}
}
return boat;

View file

@ -19,6 +19,7 @@ import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
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;
@ -26,6 +27,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(Boat.class)
public abstract class BoatMixin extends Entity implements CustomBoatTypeOverride {
@Unique
private BoatTypeOverride bcl_type = null;
@Shadow
@Final
@ -35,7 +37,8 @@ public abstract class BoatMixin extends Entity implements CustomBoatTypeOverride
super(entityType, level);
}
public void setCustomType(BoatTypeOverride type) {
@Override
public void bcl_setCustomType(BoatTypeOverride type) {
bcl_type = type;
if (type == null)
this.entityData.set(DATA_ID_TYPE, Boat.Type.OAK.ordinal());
@ -43,12 +46,13 @@ public abstract class BoatMixin extends Entity implements CustomBoatTypeOverride
this.entityData.set(DATA_ID_TYPE, bcl_type.ordinal());
}
@Override
public BoatTypeOverride bcl_getCustomType() {
bcl_type = BoatTypeOverride.byId(this.entityData.get(DATA_ID_TYPE));
return bcl_type;
}
@Inject(method = "setVariant", at = @At("HEAD"), cancellable = true)
@Inject(method = "setVariant(Lnet/minecraft/world/entity/vehicle/Boat$Type;)V", at = @At("HEAD"), cancellable = true)
void bcl_setType(Boat.Type type, CallbackInfo ci) {
if (bcl_type != null) {
this.entityData.set(DATA_ID_TYPE, bcl_type.ordinal());
@ -56,7 +60,7 @@ public abstract class BoatMixin extends Entity implements CustomBoatTypeOverride
}
}
@Inject(method = "getVariant", at = @At("HEAD"), cancellable = true)
@Inject(method = "getVariant()Lnet/minecraft/world/entity/vehicle/Boat$Type;", at = @At("HEAD"), cancellable = true)
void bcl_getBoatType(CallbackInfoReturnable<Boat.Type> cir) {
BoatTypeOverride type = BoatTypeOverride.byId(this.entityData.get(DATA_ID_TYPE));
if (type != null) {
@ -77,9 +81,9 @@ public abstract class BoatMixin extends Entity implements CustomBoatTypeOverride
@Inject(method = "readAdditionalSaveData", at = @At("HEAD"))
void bcl_readAdditionalSaveData(CompoundTag compoundTag, CallbackInfo ci) {
if (compoundTag.contains("cType")) {
this.setCustomType(BoatTypeOverride.byName(compoundTag.getString("cType")));
this.bcl_setCustomType(BoatTypeOverride.byName(compoundTag.getString("cType")));
} else {
this.setCustomType(null);
this.bcl_setCustomType(null);
}
}

View file

@ -3,23 +3,17 @@ package org.betterx.bclib.mixin.common.boat;
import org.betterx.bclib.items.boat.BoatTypeOverride;
import org.betterx.bclib.items.boat.CustomBoatTypeOverride;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.vehicle.ChestBoat;
import net.minecraft.world.item.BoatItem;
import net.minecraft.world.item.Item;
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;
@Mixin(ChestBoat.class)
public abstract class ChestBoatMixin {
@Shadow
public abstract InteractionResult interact(Player player, InteractionHand interactionHand);
@Inject(method = "getDropItem", at = @At("HEAD"), cancellable = true)
void bcl_getDropItem(CallbackInfoReturnable<Item> cir) {

View file

@ -6,10 +6,7 @@ import org.betterx.worlds.together.surfaceRules.SurfaceRuleProvider;
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
import net.minecraft.world.level.levelgen.SurfaceRules;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.*;
@Mixin(NoiseGeneratorSettings.class)
public abstract class NoiseGeneratorSettingsMixin implements SurfaceRuleProvider {
@ -31,6 +28,7 @@ public abstract class NoiseGeneratorSettingsMixin implements SurfaceRuleProvider
return this.surfaceRule;
}
@Unique
private boolean bcl_containsOverride = false;
}