Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-11-20 06:50:10 +01:00
Cleanup BlockItemRewriter & EntityRewriter
Dieser Commit ist enthalten in:
Ursprung
f33c694dd3
Commit
878230ebb1
@ -14,9 +14,9 @@ import nl.matsv.viabackwards.ViaBackwards;
|
|||||||
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11;
|
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11;
|
||||||
import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1;
|
import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1;
|
||||||
import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10;
|
import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
||||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks.ChunkSection1_9_3_4;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -47,7 +47,7 @@ public interface ViaBackwardsPlatform {
|
|||||||
default boolean isOutdated() {
|
default boolean isOutdated() {
|
||||||
Method m = null;
|
Method m = null;
|
||||||
try {
|
try {
|
||||||
m = ChunkSection1_9_3_4.class.getMethod("getBlock", int.class, int.class, int.class);
|
m = ChunkSection.class.getMethod("getBlock", int.class, int.class, int.class);
|
||||||
} catch (NoSuchMethodException ignored) {
|
} catch (NoSuchMethodException ignored) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ package nl.matsv.viabackwards.api.entities.meta;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import nl.matsv.viabackwards.api.entities.types.AbstractEntityType;
|
import nl.matsv.viabackwards.api.entities.types.AbstractEntityType;
|
||||||
|
import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
|
||||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -52,6 +53,20 @@ public class MetaHandlerSettings {
|
|||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void handleIndexChange(final int newIndex) {
|
||||||
|
handle(e -> {
|
||||||
|
Metadata data = e.getData();
|
||||||
|
data.setId(newIndex);
|
||||||
|
return data;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removed() {
|
||||||
|
handle(e -> {
|
||||||
|
throw new RemovedValueException();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasHandler() {
|
public boolean hasHandler() {
|
||||||
return handler != null;
|
return handler != null;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,8 @@ package nl.matsv.viabackwards.api.rewriters;
|
|||||||
import nl.matsv.viabackwards.api.BackwardsProtocol;
|
import nl.matsv.viabackwards.api.BackwardsProtocol;
|
||||||
import nl.matsv.viabackwards.utils.Block;
|
import nl.matsv.viabackwards.utils.Block;
|
||||||
import nl.matsv.viabackwards.utils.ItemUtil;
|
import nl.matsv.viabackwards.utils.ItemUtil;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
||||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||||
import us.myles.viaversion.libs.opennbt.conversion.builtin.CompoundTagConverter;
|
import us.myles.viaversion.libs.opennbt.conversion.builtin.CompoundTagConverter;
|
||||||
import us.myles.viaversion.libs.opennbt.tag.builtin.*;
|
import us.myles.viaversion.libs.opennbt.tag.builtin.*;
|
||||||
@ -97,6 +99,27 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void handleChunk(Chunk chunk) {
|
||||||
|
for (int i = 0; i < chunk.getSections().length; i++) {
|
||||||
|
ChunkSection section = chunk.getSections()[i];
|
||||||
|
if (section == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (int x = 0; x < 16; x++) {
|
||||||
|
for (int y = 0; y < 16; y++) {
|
||||||
|
for (int z = 0; z < 16; z++) {
|
||||||
|
int block = section.getBlock(x, y, z);
|
||||||
|
int btype = block >> 4;
|
||||||
|
if (containsBlock(btype)) {
|
||||||
|
Block b = handleBlock(btype, block & 15); // Type / data
|
||||||
|
section.setBlock(x, y, z, b.getId(), b.getData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean containsBlock(int block) {
|
protected boolean containsBlock(int block) {
|
||||||
return blockRewriter.containsKey(block);
|
return blockRewriter.containsKey(block);
|
||||||
}
|
}
|
||||||
@ -123,4 +146,5 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
|
|||||||
private String getProtocolName() {
|
private String getProtocolName() {
|
||||||
return getProtocol().getClass().getSimpleName();
|
return getProtocol().getClass().getSimpleName();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
|||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks.Chunk1_9_3_4;
|
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks.Chunk1_9_3_4;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks.ChunkSection1_9_3_4;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
|
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||||
|
|
||||||
@ -170,24 +169,7 @@ public class BlockItemPackets extends BlockItemRewriter<Protocol1_10To1_11> {
|
|||||||
Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld); // Use the 1.10 Chunk type since nothing changed.
|
Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld); // Use the 1.10 Chunk type since nothing changed.
|
||||||
Chunk1_9_3_4 chunk = (Chunk1_9_3_4) wrapper.passthrough(type);
|
Chunk1_9_3_4 chunk = (Chunk1_9_3_4) wrapper.passthrough(type);
|
||||||
|
|
||||||
for (int i = 0; i < chunk.getSections().length; i++) {
|
handleChunk(chunk);
|
||||||
ChunkSection1_9_3_4 section = chunk.getSections()[i];
|
|
||||||
if (section == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
for (int x = 0; x < 16; x++) {
|
|
||||||
for (int y = 0; y < 16; y++) {
|
|
||||||
for (int z = 0; z < 16; z++) {
|
|
||||||
int block = section.getBlock(x, y, z);
|
|
||||||
int btype = block >> 4;
|
|
||||||
if (containsBlock(btype)) {
|
|
||||||
Block b = handleBlock(btype, block & 15); // Type / data
|
|
||||||
section.setBlock(x, y, z, b.getId(), b.getData());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -386,10 +386,7 @@ public class EntityPackets extends EntityRewriter<Protocol1_10To1_11> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Handle skeleton swing
|
// Handle skeleton swing
|
||||||
registerMetaHandler().filter(EntityType.ABSTRACT_SKELETON, true, 12).handle(e -> {
|
registerMetaHandler().filter(EntityType.ABSTRACT_SKELETON, true, 12).handleIndexChange(13);
|
||||||
e.getData().setId(13);
|
|
||||||
return e.getData();
|
|
||||||
});
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
ZOMBIE CHANGES
|
ZOMBIE CHANGES
|
||||||
@ -449,23 +446,13 @@ public class EntityPackets extends EntityRewriter<Protocol1_10To1_11> {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Handle Horse (Correct owner)
|
// Handle Horse (Correct owner)
|
||||||
registerMetaHandler().filter(EntityType.ABSTRACT_HORSE, true, 14).handle(e -> {
|
registerMetaHandler().filter(EntityType.ABSTRACT_HORSE, true, 14).handleIndexChange(16);
|
||||||
Metadata data = e.getData();
|
|
||||||
data.setId(16);
|
|
||||||
return data;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle horse armor
|
// Handle horse armor
|
||||||
registerMetaHandler().filter(EntityType.HORSE, 16).handle(e -> {
|
registerMetaHandler().filter(EntityType.HORSE, 16).handleIndexChange(17);
|
||||||
Metadata data = e.getData();
|
|
||||||
data.setId(17);
|
|
||||||
return data;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle chested horse - flag is still sent in horse flags
|
// Handle chested horse - flag is still sent in horse flags
|
||||||
registerMetaHandler().filter(EntityType.CHESTED_HORSE, true, 15).handle(e -> {
|
registerMetaHandler().filter(EntityType.CHESTED_HORSE, true, 15).removed();
|
||||||
throw new RemovedValueException();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Get rid of Liama metadata TODO maybe for some special magic in the future?
|
// Get rid of Liama metadata TODO maybe for some special magic in the future?
|
||||||
registerMetaHandler().filter(EntityType.LIAMA).handle(e -> {
|
registerMetaHandler().filter(EntityType.LIAMA).handle(e -> {
|
||||||
@ -485,9 +472,7 @@ public class EntityPackets extends EntityRewriter<Protocol1_10To1_11> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// handle new Shulker color meta
|
// handle new Shulker color meta
|
||||||
registerMetaHandler().filter(EntityType.SHULKER, 15).handle(e -> {
|
registerMetaHandler().filter(EntityType.SHULKER, 15).removed();
|
||||||
throw new RemovedValueException();
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ import nl.matsv.viabackwards.ViaBackwards;
|
|||||||
import nl.matsv.viabackwards.api.entities.storage.EntityData;
|
import nl.matsv.viabackwards.api.entities.storage.EntityData;
|
||||||
import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
|
import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
|
||||||
import nl.matsv.viabackwards.api.entities.types.AbstractEntityType;
|
import nl.matsv.viabackwards.api.entities.types.AbstractEntityType;
|
||||||
import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
|
|
||||||
import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
|
import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
|
||||||
import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1;
|
import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
@ -342,13 +341,9 @@ public class EntityPackets extends EntityRewriter<Protocol1_11To1_11_1> {
|
|||||||
protected void registerRewrites() {
|
protected void registerRewrites() {
|
||||||
// TODO tipped arrows check no particles changes?
|
// TODO tipped arrows check no particles changes?
|
||||||
// Handle non-existing firework metadata (index 7 entity id for boosting)
|
// Handle non-existing firework metadata (index 7 entity id for boosting)
|
||||||
registerMetaHandler().filter(EntityType.FIREWORK, 7).handle(e -> {
|
registerMetaHandler().filter(EntityType.FIREWORK, 7).removed();
|
||||||
throw new RemovedValueException();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle non-existing pig metadata (index 14 - boost time)
|
// Handle non-existing pig metadata (index 14 - boost time)
|
||||||
registerMetaHandler().filter(EntityType.PIG, 14).handle(e -> {
|
registerMetaHandler().filter(EntityType.PIG, 14).removed();
|
||||||
throw new RemovedValueException();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
|||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks.Chunk1_9_3_4;
|
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks.Chunk1_9_3_4;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks.ChunkSection1_9_3_4;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
|
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||||
|
|
||||||
@ -170,24 +169,7 @@ public class BlockItemPackets extends BlockItemRewriter<Protocol1_9_4To1_10> {
|
|||||||
Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld);
|
Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld);
|
||||||
Chunk1_9_3_4 chunk = (Chunk1_9_3_4) wrapper.passthrough(type);
|
Chunk1_9_3_4 chunk = (Chunk1_9_3_4) wrapper.passthrough(type);
|
||||||
|
|
||||||
for (int i = 0; i < chunk.getSections().length; i++) {
|
handleChunk(chunk);
|
||||||
ChunkSection1_9_3_4 section = chunk.getSections()[i];
|
|
||||||
if (section == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
for (int x = 0; x < 16; x++) {
|
|
||||||
for (int y = 0; y < 16; y++) {
|
|
||||||
for (int z = 0; z < 16; z++) {
|
|
||||||
int block = section.getBlock(x, y, z);
|
|
||||||
int btype = block >> 4;
|
|
||||||
if (containsBlock(btype)) {
|
|
||||||
Block b = handleBlock(btype, block & 15); // Type / data
|
|
||||||
section.setBlock(x, y, z, b.getId(), b.getData());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
2
pom.xml
2
pom.xml
@ -65,7 +65,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>us.myles</groupId>
|
<groupId>us.myles</groupId>
|
||||||
<artifactId>viaversion</artifactId>
|
<artifactId>viaversion</artifactId>
|
||||||
<version>1.0.5-1_12pre5</version>
|
<version>1.1.0-1_12pre7</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren