1.20.6 Initial Update

New Decompiler
Runtime Official mappings
ItemStacks arnt Capability providers anymore, use Vanilla's system.

Co-authored-by: RealMangoRage <[email protected]>
Co-authored-by: Paint_Ninja <[email protected]>
This commit is contained in:
committed 2024-04-30 11:42:52 -07:00
1 parent e1fa61080a
commit 7b782e5b05
1114 files changed
+24245 -28536

No files matched your search

@@ -15,6 +15,7 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.resources.ResourceKey;
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.Level;
import net.minecraftforge.server.ServerLifecycleHooks;
@@ -27,8 +28,7 @@ import org.jetbrains.annotations.Nullable;
* Unlike Block, which only one object can exist per coordinate, BlockSnapshot
* can exist multiple times for any given Block.
*/
public class BlockSnapshot
{
public class BlockSnapshot {
private static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("forge.debugBlockSnapshot", "false"));
private final ResourceKey<Level> dim;
@@ -42,8 +42,7 @@ public class BlockSnapshot
private WeakReference<LevelAccessor> level;
private String toString = null;
private BlockSnapshot(ResourceKey<Level> dim, LevelAccessor level, BlockPos pos, BlockState state, @Nullable CompoundTag nbt, int flags)
{
private BlockSnapshot(ResourceKey<Level> dim, LevelAccessor level, BlockPos pos, BlockState state, @Nullable CompoundTag nbt, int flags) {
this.dim = dim;
this.pos = pos.immutable();
this.block = state;
@@ -56,75 +55,64 @@ public class BlockSnapshot
System.out.println("Created " + this.toString());
}
public static BlockSnapshot create(ResourceKey<Level> dim, LevelAccessor world, BlockPos pos)
{
public static BlockSnapshot create(ResourceKey<Level> dim, LevelAccessor world, BlockPos pos) {
return create(dim, world, pos, 3);
}
public static BlockSnapshot create(ResourceKey<Level> dim, LevelAccessor world, BlockPos pos, int flag)
{
return new BlockSnapshot(dim, world, pos, world.getBlockState(pos), getBlockEntityTag(world.getBlockEntity(pos)), flag);
public static BlockSnapshot create(ResourceKey<Level> dim, LevelAccessor world, BlockPos pos, int flag) {
return new BlockSnapshot(dim, world, pos, world.getBlockState(pos), getBlockEntityTag(world.getBlockEntity(pos), world.registryAccess()), flag);
}
@Nullable
private static CompoundTag getBlockEntityTag(@Nullable BlockEntity te)
{
return te == null ? null : te.saveWithFullMetadata();
private static CompoundTag getBlockEntityTag(@Nullable BlockEntity te, HolderLookup.Provider lookup) {
return te == null ? null : te.saveCustomAndMetadata(lookup);
}
public BlockState getCurrentBlock()
{
public BlockState getCurrentBlock() {
LevelAccessor world = getLevel();
return world == null ? Blocks.AIR.defaultBlockState() : world.getBlockState(this.pos);
}
@Nullable
public LevelAccessor getLevel()
{
public LevelAccessor getLevel() {
LevelAccessor world = this.level != null ? this.level.get() : null;
if (world == null)
{
if (world == null) {
world = ServerLifecycleHooks.getCurrentServer().getLevel(this.dim);
this.level = new WeakReference<LevelAccessor>(world);
}
return world;
}
public BlockState getReplacedBlock()
{
public BlockState getReplacedBlock() {
return this.block;
}
/*
@Nullable
public BlockEntity getBlockEntity()
{
public BlockEntity getBlockEntity() {
return getTag() != null ? BlockEntity.loadStatic(getPos(), getReplacedBlock(), getTag()) : null;
}
*/
public boolean restore()
{
public boolean restore() {
return restore(false);
}
public boolean restore(boolean force)
{
public boolean restore(boolean force) {
return restore(force, true);
}
public boolean restore(boolean force, boolean notifyNeighbors)
{
public boolean restore(boolean force, boolean notifyNeighbors) {
return restoreToLocation(getLevel(), getPos(), force, notifyNeighbors);
}
public boolean restoreToLocation(LevelAccessor world, BlockPos pos, boolean force, boolean notifyNeighbors)
{
public boolean restoreToLocation(LevelAccessor world, BlockPos pos, boolean force, boolean notifyNeighbors) {
BlockState current = getCurrentBlock();
BlockState replaced = getReplacedBlock();
int flags = notifyNeighbors ? Block.UPDATE_ALL : Block.UPDATE_CLIENTS;
if (current != replaced)
{
if (current != replaced) {
if (force)
world.setBlock(pos, replaced, flags);
else
@@ -136,12 +124,10 @@ public class BlockSnapshot
((Level)world).sendBlockUpdated(pos, current, replaced, flags);
BlockEntity te = null;
if (getTag() != null)
{
if (getTag() != null) {
te = world.getBlockEntity(pos);
if (te != null)
{
te.load(getTag());
if (te != null) {
te.loadWithComponents(nbt, world.registryAccess());
te.setChanged();
}
}
@@ -152,8 +138,7 @@ public class BlockSnapshot
}
@Override
public boolean equals(Object obj)
{
public boolean equals(Object obj) {
if (obj == this)
return true;
if (obj == null || getClass() != obj.getClass())
@@ -168,8 +153,7 @@ public class BlockSnapshot
}
@Override
public int hashCode()
{
public int hashCode() {
int hash = 7;
hash = 73 * hash + this.dim.hashCode();
hash = 73 * hash + this.pos.hashCode();
@@ -180,10 +164,8 @@ public class BlockSnapshot
}
@Override
public String toString()
{
if (toString == null)
{
public String toString() {
if (toString == null) {
this.toString =
"BlockSnapshot[" +
"World:" + this.dim.location() + ',' +
@@ -5,6 +5,7 @@
package net.minecraftforge.common.util;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.saveddata.SavedData;
@@ -15,8 +16,7 @@ public class DummySavedData extends SavedData {
}
@Override
public CompoundTag save(final CompoundTag compound) {
// NOOP
public CompoundTag save(final CompoundTag compound, HolderLookup.Provider lookup) {
return null;
}
}
@@ -5,14 +5,22 @@
package net.minecraftforge.common.util;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.Tag;
/**
* An interface designed to unify various things in the Minecraft
* code base that can be serialized to and from a NBT tag.
*
* @deprecated // Mojang has switched most things to Codecs and registry context, probably worth deleting this.
*/
public interface INBTSerializable<T extends Tag>
{
T serializeNBT();
void deserializeNBT(T nbt);
public interface INBTSerializable<T extends Tag> {
default T serializeNBT() { return null; }
default T serializeNBT(HolderLookup.Provider registryAccess) {
return serializeNBT();
}
default void deserializeNBT(T nbt) { }
default void deserializeNBT(HolderLookup.Provider registryAccess, T nbt) {
deserializeNBT(nbt);
}
}
@@ -5,6 +5,8 @@
package net.minecraftforge.common.util;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.HolderLookup.Provider;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.saveddata.SavedData;
import net.minecraft.world.level.storage.DimensionDataStorage;
@@ -30,7 +32,7 @@ public class LevelCapabilityData extends SavedData {
}
@Override
public CompoundTag save(CompoundTag nbt) {
public CompoundTag save(CompoundTag nbt, HolderLookup.Provider provider) {
if (serializable != null)
nbt = serializable.serializeNBT();
return nbt;
@@ -52,7 +54,7 @@ public class LevelCapabilityData extends SavedData {
public static LevelCapabilityData compute(DimensionDataStorage data, @Nullable INBTSerializable<CompoundTag> caps) {
var factory = new Factory<>(
() -> new LevelCapabilityData(caps),
(tag) -> {
(tag, lookup) -> {
var ret = new LevelCapabilityData(caps);
ret.read(tag);
return ret;
@@ -47,11 +47,8 @@ public class PacketLogger {
if (packet instanceof ClientboundFinishConfigurationPacket)
enabled = false;
if (packet instanceof ICustomPacket) {
var data = new FriendlyByteBuf(Unpooled.buffer());
packet.write(data);
LOGGER.info(MARKER, "{} {} {}\n{}", side(side), dir(flow), packet.getClass().getName(), HexDumper.dump(data));
if (packet instanceof ICustomPacket custom && custom.getInternalData() != null) {
LOGGER.info(MARKER, "{} {} {}\n{}", side(side), dir(flow), packet.getClass().getName(), HexDumper.dump(custom.getInternalData()));
} else {
LOGGER.info(MARKER, "{} {} {}", side(side), dir(flow), packet.getClass().getName());
}