mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-21 00:01:29 +00:00
working 1.20.6
This commit is contained in:
+10
-2
@@ -25,10 +25,13 @@ import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryWrapper;
|
||||
import net.minecraft.registry.RegistryWrapper.Impl;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.dfsek.terra.api.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.inventory.Item;
|
||||
@@ -43,8 +46,13 @@ public class MinecraftItemHandle implements ItemHandle {
|
||||
try {
|
||||
return (Item) new ItemStackArgumentType(new CommandRegistryAccess() {
|
||||
@Override
|
||||
public <T> RegistryWrapper<T> createWrapper(RegistryKey<? extends Registry<T>> registryRef) {
|
||||
return CommonPlatform.get().getServer().getRegistryManager().getWrapperOrThrow(registryRef);
|
||||
public Stream<RegistryKey<? extends Registry<?>>> streamAllRegistryKeys() {
|
||||
return CommonPlatform.get().getServer().getRegistryManager().streamAllRegistryKeys();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<Impl<T>> getOptionalWrapper(RegistryKey<? extends Registry<? extends T>> registryRef) {
|
||||
return Optional.of(CommonPlatform.get().getServer().getRegistryManager().getWrapperOrThrow(registryRef));
|
||||
}
|
||||
}).parse(new StringReader(data)).getItem();
|
||||
} catch(CommandSyntaxException e) {
|
||||
|
||||
+2
-2
@@ -50,7 +50,7 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
|
||||
public abstract MobSpawnerLogic getLogic();
|
||||
|
||||
@Shadow
|
||||
public abstract void setEntityType(net.minecraft.entity.EntityType<?> entityType, Random random);
|
||||
public abstract void method_46408(net.minecraft.entity.EntityType<?> entityType, Random random);
|
||||
|
||||
public EntityType terra$getSpawnedType() {
|
||||
return (EntityType) Registries.ENTITY_TYPE.get(
|
||||
@@ -64,7 +64,7 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
|
||||
} else {
|
||||
rand = Random.create();
|
||||
}
|
||||
setEntityType((net.minecraft.entity.EntityType<?>) creatureType, rand);
|
||||
method_46408((net.minecraft.entity.EntityType<?>) creatureType, rand);
|
||||
}
|
||||
|
||||
public int terra$getDelay() {
|
||||
|
||||
+3
-2
@@ -30,7 +30,7 @@ import com.dfsek.terra.api.inventory.ItemStack;
|
||||
@Implements(@Interface(iface = com.dfsek.terra.api.inventory.Item.class, prefix = "terra$"))
|
||||
public abstract class ItemMixin {
|
||||
@Shadow
|
||||
public abstract int getMaxDamage();
|
||||
public abstract net.minecraft.item.ItemStack getDefaultStack();
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public ItemStack terra$newItemStack(int amount) {
|
||||
@@ -38,6 +38,7 @@ public abstract class ItemMixin {
|
||||
}
|
||||
|
||||
public double terra$getMaxDurability() {
|
||||
return getMaxDamage();
|
||||
//TODO verify this is correct
|
||||
return getDefaultStack().getMaxDamage();
|
||||
}
|
||||
}
|
||||
|
||||
+18
-2
@@ -17,9 +17,15 @@
|
||||
|
||||
package com.dfsek.terra.mod.mixin.implementations.terra.inventory.item;
|
||||
|
||||
import net.minecraft.component.Component;
|
||||
import net.minecraft.component.ComponentChanges;
|
||||
import net.minecraft.component.ComponentMap;
|
||||
import net.minecraft.component.ComponentMapImpl;
|
||||
import net.minecraft.component.DataComponentType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
@@ -46,7 +52,11 @@ public abstract class ItemStackMixin {
|
||||
public abstract boolean isDamageable();
|
||||
|
||||
@Shadow
|
||||
public abstract void setNbt(@Nullable NbtCompound tag);
|
||||
public abstract ComponentMap getComponents();
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private ComponentMapImpl components;
|
||||
|
||||
public int terra$getAmount() {
|
||||
return getCount();
|
||||
@@ -66,7 +76,13 @@ public abstract class ItemStackMixin {
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public void terra$setItemMeta(ItemMeta meta) {
|
||||
setNbt(((ItemStack) (Object) meta).getNbt());
|
||||
ComponentChanges.Builder builder = ComponentChanges.builder();
|
||||
this.getComponents().getTypes().forEach(builder::remove);
|
||||
|
||||
ComponentMap components = ((ItemStack) (Object) meta).getComponents();
|
||||
components.forEach(builder::add);
|
||||
|
||||
this.components.applyChanges(builder.build());
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
|
||||
+6
-4
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.dfsek.terra.mod.mixin.implementations.terra.inventory.meta;
|
||||
|
||||
import net.minecraft.component.type.ItemEnchantmentsComponent;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtList;
|
||||
@@ -42,7 +43,7 @@ public abstract class ItemStackMetaMixin {
|
||||
public abstract boolean hasEnchantments();
|
||||
|
||||
@Shadow
|
||||
public abstract NbtList getEnchantments();
|
||||
public abstract ItemEnchantmentsComponent getEnchantments();
|
||||
|
||||
@Shadow
|
||||
public abstract void addEnchantment(net.minecraft.enchantment.Enchantment enchantment, int level);
|
||||
@@ -56,9 +57,10 @@ public abstract class ItemStackMetaMixin {
|
||||
if(!hasEnchantments()) return Collections.emptyMap();
|
||||
Map<Enchantment, Integer> map = new HashMap<>();
|
||||
|
||||
getEnchantments().forEach(enchantment -> {
|
||||
NbtCompound eTag = (NbtCompound) enchantment;
|
||||
map.put((Enchantment) Registries.ENCHANTMENT.get(eTag.getInt("id")), eTag.getInt("lvl"));
|
||||
ItemEnchantmentsComponent enchantments = getEnchantments();
|
||||
enchantments.getEnchantments().forEach(enchantment -> {
|
||||
net.minecraft.enchantment.Enchantment enchantmentValue = enchantment.value();
|
||||
map.put((Enchantment) enchantmentValue, enchantments.getLevel(enchantmentValue));
|
||||
});
|
||||
return map;
|
||||
}
|
||||
|
||||
+3
-1
@@ -17,6 +17,8 @@
|
||||
|
||||
package com.dfsek.terra.mod.mixin.implementations.terra.world;
|
||||
|
||||
import com.dfsek.terra.mod.mixin.invoke.FluidBlockInvoker;
|
||||
|
||||
import net.minecraft.block.FluidBlock;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -88,7 +90,7 @@ public abstract class ChunkRegionMixin {
|
||||
((ChunkRegion) (Object) this).setBlockState(pos, (net.minecraft.block.BlockState) data, physics ? 3 : 1042);
|
||||
if(physics && ((net.minecraft.block.BlockState) data).getBlock() instanceof FluidBlock) {
|
||||
fluidTickScheduler.scheduleTick(
|
||||
OrderedTick.create(((FluidBlock) ((net.minecraft.block.BlockState) data).getBlock()).getFluidState(
|
||||
OrderedTick.create((((FluidBlockInvoker) ((net.minecraft.block.BlockState) data).getBlock())).invokeGetFluidState(
|
||||
(net.minecraft.block.BlockState) data).getFluid(), pos));
|
||||
}
|
||||
}
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.dfsek.terra.mod.mixin.invoke;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.FluidBlock;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
|
||||
@Mixin(FluidBlock.class)
|
||||
public interface FluidBlockInvoker {
|
||||
@Invoker("getFluidState")
|
||||
public FluidState invokeGetFluidState(BlockState state);
|
||||
}
|
||||
+9
-2
@@ -3,9 +3,12 @@ package com.dfsek.terra.mod.mixin.lifecycle;
|
||||
import net.minecraft.registry.DynamicRegistryManager;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.registry.ReloadableRegistries;
|
||||
import net.minecraft.server.DataPackContents;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
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.CallbackInfo;
|
||||
@@ -16,11 +19,15 @@ import com.dfsek.terra.mod.util.TagUtil;
|
||||
|
||||
@Mixin(DataPackContents.class)
|
||||
public class DataPackContentsMixin {
|
||||
@Shadow
|
||||
@Final
|
||||
private ReloadableRegistries.Lookup reloadableRegistries;
|
||||
/*
|
||||
* #refresh populates all tags in the registries
|
||||
*/
|
||||
@Inject(method = "refresh(Lnet/minecraft/registry/DynamicRegistryManager;)V", at = @At("RETURN"))
|
||||
private void injectReload(DynamicRegistryManager dynamicRegistryManager, CallbackInfo ci) {
|
||||
@Inject(method = "refresh()V", at = @At("RETURN"))
|
||||
private void injectReload(CallbackInfo ci) {
|
||||
DynamicRegistryManager.Immutable dynamicRegistryManager = this.reloadableRegistries.getRegistryManager();
|
||||
TagUtil.registerWorldPresetTags(dynamicRegistryManager.get(RegistryKeys.WORLD_PRESET));
|
||||
|
||||
Registry<Biome> biomeRegistry = dynamicRegistryManager.get(RegistryKeys.BIOME);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
accessWidener v1 named
|
||||
accessible class net/minecraft/world/biome/Biome$Weather
|
||||
accessible class net/minecraft/world/gen/WorldPresets$Registrar
|
||||
accessible method net/minecraft/block/FluidBlock getFluidState (Lnet/minecraft/block/BlockState;)Lnet/minecraft/fluid/FluidState
|
||||
accessible class net/minecraft/registry/RegistryLoader$Loader
|
||||
@@ -2,7 +2,7 @@
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "com.dfsek.terra.mod.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"mixins": [
|
||||
"access.BiomeAccessor",
|
||||
"access.MobSpawnerLogicAccessor",
|
||||
|
||||
Reference in New Issue
Block a user