3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-26 00:00:33 +01:00

Cleanup BlockItemRewriter & EntityRewriter

Dieser Commit ist enthalten in:
Matsv 2017-06-01 19:09:48 +02:00
Ursprung f33c694dd3
Commit 878230ebb1
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 97CEC2A2EA31350F
8 geänderte Dateien mit 51 neuen und 68 gelöschten Zeilen

Datei anzeigen

@ -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_11to1_11_1.Protocol1_11To1_11_1;
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.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.util.Collections;
@ -47,7 +47,7 @@ public interface ViaBackwardsPlatform {
default boolean isOutdated() {
Method m = null;
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) {
}

Datei anzeigen

@ -13,6 +13,7 @@ package nl.matsv.viabackwards.api.entities.meta;
import lombok.Getter;
import lombok.ToString;
import nl.matsv.viabackwards.api.entities.types.AbstractEntityType;
import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import java.util.List;
@ -52,6 +53,20 @@ public class MetaHandlerSettings {
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() {
return handler != null;
}

Datei anzeigen

@ -13,6 +13,8 @@ package nl.matsv.viabackwards.api.rewriters;
import nl.matsv.viabackwards.api.BackwardsProtocol;
import nl.matsv.viabackwards.utils.Block;
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.libs.opennbt.conversion.builtin.CompoundTagConverter;
import us.myles.viaversion.libs.opennbt.tag.builtin.*;
@ -97,6 +99,27 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
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) {
return blockRewriter.containsKey(block);
}
@ -123,4 +146,5 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
private String getProtocolName() {
return getProtocol().getClass().getSimpleName();
}
}

Datei anzeigen

@ -22,7 +22,6 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
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.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_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_4 chunk = (Chunk1_9_3_4) wrapper.passthrough(type);
for (int i = 0; i < chunk.getSections().length; i++) {
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());
}
}
}
}
}
handleChunk(chunk);
}
});
}

Datei anzeigen

@ -386,10 +386,7 @@ public class EntityPackets extends EntityRewriter<Protocol1_10To1_11> {
});
// Handle skeleton swing
registerMetaHandler().filter(EntityType.ABSTRACT_SKELETON, true, 12).handle(e -> {
e.getData().setId(13);
return e.getData();
});
registerMetaHandler().filter(EntityType.ABSTRACT_SKELETON, true, 12).handleIndexChange(13);
/*
ZOMBIE CHANGES
@ -449,23 +446,13 @@ public class EntityPackets extends EntityRewriter<Protocol1_10To1_11> {
*/
// Handle Horse (Correct owner)
registerMetaHandler().filter(EntityType.ABSTRACT_HORSE, true, 14).handle(e -> {
Metadata data = e.getData();
data.setId(16);
return data;
});
registerMetaHandler().filter(EntityType.ABSTRACT_HORSE, true, 14).handleIndexChange(16);
// Handle horse armor
registerMetaHandler().filter(EntityType.HORSE, 16).handle(e -> {
Metadata data = e.getData();
data.setId(17);
return data;
});
registerMetaHandler().filter(EntityType.HORSE, 16).handleIndexChange(17);
// Handle chested horse - flag is still sent in horse flags
registerMetaHandler().filter(EntityType.CHESTED_HORSE, true, 15).handle(e -> {
throw new RemovedValueException();
});
registerMetaHandler().filter(EntityType.CHESTED_HORSE, true, 15).removed();
// Get rid of Liama metadata TODO maybe for some special magic in the future?
registerMetaHandler().filter(EntityType.LIAMA).handle(e -> {
@ -485,9 +472,7 @@ public class EntityPackets extends EntityRewriter<Protocol1_10To1_11> {
});
// handle new Shulker color meta
registerMetaHandler().filter(EntityType.SHULKER, 15).handle(e -> {
throw new RemovedValueException();
});
registerMetaHandler().filter(EntityType.SHULKER, 15).removed();
}

Datei anzeigen

@ -14,7 +14,6 @@ import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.entities.storage.EntityData;
import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
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.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1;
import us.myles.ViaVersion.api.PacketWrapper;
@ -342,13 +341,9 @@ public class EntityPackets extends EntityRewriter<Protocol1_11To1_11_1> {
protected void registerRewrites() {
// TODO tipped arrows check no particles changes?
// Handle non-existing firework metadata (index 7 entity id for boosting)
registerMetaHandler().filter(EntityType.FIREWORK, 7).handle(e -> {
throw new RemovedValueException();
});
registerMetaHandler().filter(EntityType.FIREWORK, 7).removed();
// Handle non-existing pig metadata (index 14 - boost time)
registerMetaHandler().filter(EntityType.PIG, 14).handle(e -> {
throw new RemovedValueException();
});
registerMetaHandler().filter(EntityType.PIG, 14).removed();
}
}

Datei anzeigen

@ -22,7 +22,6 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
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.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_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_4 chunk = (Chunk1_9_3_4) wrapper.passthrough(type);
for (int i = 0; i < chunk.getSections().length; i++) {
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());
}
}
}
}
}
handleChunk(chunk);
}
});
}

Datei anzeigen

@ -65,7 +65,7 @@
<dependency>
<groupId>us.myles</groupId>
<artifactId>viaversion</artifactId>
<version>1.0.5-1_12pre5</version>
<version>1.1.0-1_12pre7</version>
<scope>provided</scope>
</dependency>
</dependencies>