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

🔧 Start working on flower pot special treatment

Dieser Commit ist enthalten in:
Matsv 2019-03-16 15:11:23 +01:00
Ursprung 092057431c
Commit 0497ce198d
3 geänderte Dateien mit 95 neuen und 26 gelöschten Zeilen

Datei anzeigen

@ -13,8 +13,8 @@ package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handler
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.viaversion.libs.opennbt.tag.builtin.ByteTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.IntTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag;
import java.util.Map;
@ -53,6 +53,10 @@ public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsB
flowers.put(id, new Pair<>(identifier, data));
}
public static boolean isFlowah(int id) {
return flowers.containsKey(id);
}
public Pair<String, Byte> getOrDefault(int blockId) {
if (flowers.containsKey(blockId))
return flowers.get(blockId);
@ -66,7 +70,7 @@ public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsB
Pair<String, Byte> item = getOrDefault(blockId);
tag.put(new StringTag("Item", item.getKey()));
tag.put(new ByteTag("Data", item.getValue()));
tag.put(new IntTag("Data", item.getValue()));
return tag;
}

Datei anzeigen

@ -14,11 +14,13 @@ import com.google.common.base.Optional;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.rewriters.BlockItemRewriter;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.FlowerPotHandler;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.BackwardsMappings;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.BlockChangeRecord;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
@ -58,6 +60,20 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
return 1 << 4;
}
public static boolean isDamageable(int id) {
return id >= 256 && id <= 259 // iron shovel, pickaxe, axe, flint and steel
|| id == 261 // bow
|| id >= 267 && id <= 279 // iron sword, wooden+stone+diamond swords, shovels, pickaxes, axes
|| id >= 283 && id <= 286 // gold sword, shovel, pickaxe, axe
|| id >= 290 && id <= 294 // hoes
|| id >= 298 && id <= 317 // armors
|| id == 346 // fishing rod
|| id == 359 // shears
|| id == 398 // carrot on a stick
|| id == 442 // shield
|| id == 443; // elytra
}
@Override
protected void registerPackets(Protocol1_12_2To1_13 protocol) {
NBT_TAG_NAME = "ViaBackwards|" + protocol.getClass().getSimpleName();
@ -140,12 +156,16 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int blockState = wrapper.read(Type.VAR_INT);
Position position = wrapper.get(Type.POSITION, 0);
// Store blocks for
// Store blocks
BackwardsBlockStorage storage = wrapper.user().get(BackwardsBlockStorage.class);
storage.checkAndStore(wrapper.get(Type.POSITION, 0), blockState);
storage.checkAndStore(position, blockState);
wrapper.write(Type.VAR_INT, toOldId(blockState));
// Flower pot special treatment
flowerPotSpecialTreatment(wrapper.user(), blockState, position);
}
});
}
@ -175,6 +195,9 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
// Store if needed
storage.checkAndStore(position, block);
// Flower pot special treatment
flowerPotSpecialTreatment(wrapper.user(), block, position);
// Change to old id
record.setBlockId(toOldId(block));
}
@ -267,14 +290,40 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
continue;
}
// Flower pots require a special treatment, they are no longer block entities :(
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
int block = section.getFlatBlock(x, y, z);
// Check if the block is a flower
if (FlowerPotHandler.isFlowah(block)) {
Position pos = new Position(
(long) (x + (chunk.getX() << 4)),
(long) (y + (i << 4)),
(long) (z + (chunk.getZ() << 4))
);
// Store block
storage.checkAndStore(pos, block);
CompoundTag nbt = provider.transform(wrapper.user(), pos, "minecraft:flower_pot");
chunk.getBlockEntities().add(nbt);
}
}
}
}
for (int p = 0; p < section.getPaletteSize(); p++) {
int old = section.getPaletteEntry(p);
if (old != 0) {
section.setPaletteEntry(p, toOldId(old));
int oldId = toOldId(old);
section.setPaletteEntry(p, oldId);
}
}
}
// Rewrite biome id 255 to plains
if (chunk.isBiomeData()) {
for (int i = 0; i < 256; i++) {
@ -666,9 +715,9 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
}
}
}
if(dummyEnchatment && enchantments.size() > 0) {
if (dummyEnchatment && enchantments.size() > 0) {
ByteTag hideFlags = tag.get("HideFlags");
if(hideFlags == null){
if (hideFlags == null) {
hideFlags = new ByteTag("HideFlags");
tag.put(new ByteTag(NBT_TAG_NAME + "|noHideFlags"));
}
@ -892,13 +941,13 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
ListTag ench = tag.get("ench");
ListTag enchantments = new ListTag("Enchantments", CompoundTag.class);
boolean dummyEnchatment = false;
if(tag.get(NBT_TAG_NAME + "|dummyEnchatment") instanceof ByteTag){
if (tag.get(NBT_TAG_NAME + "|dummyEnchatment") instanceof ByteTag) {
ByteTag dummy = tag.get(NBT_TAG_NAME + "|dummyEnchatment");
if(tag.get("HideFlags") instanceof ByteTag){
if(tag.get(NBT_TAG_NAME + "|noHideFlags") instanceof ByteTag){
if (tag.get("HideFlags") instanceof ByteTag) {
if (tag.get(NBT_TAG_NAME + "|noHideFlags") instanceof ByteTag) {
tag.remove("HideFlags");
tag.remove(NBT_TAG_NAME + "|noHideFlags");
}else{
} else {
ByteTag hideFlags = tag.get("HideFlags");
hideFlags.setValue(dummy.getValue());
}
@ -910,7 +959,7 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
if (enchEntry instanceof CompoundTag) {
CompoundTag enchantmentEntry = new CompoundTag("");
short oldId = ((Number) ((CompoundTag) enchEntry).get("id").getValue()).shortValue();
if(dummyEnchatment && oldId == 0){
if (dummyEnchatment && oldId == 0) {
continue; //Skip dummy enchatment
}
String newId = MappingData.oldEnchantmentsIds.get(oldId);
@ -1049,22 +1098,19 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
return item;
}
public static boolean isDamageable(int id) {
return id >= 256 && id <= 259 // iron shovel, pickaxe, axe, flint and steel
|| id == 261 // bow
|| id >= 267 && id <= 279 // iron sword, wooden+stone+diamond swords, shovels, pickaxes, axes
|| id >= 283 && id <= 286 // gold sword, shovel, pickaxe, axe
|| id >= 290 && id <= 294 // hoes
|| id >= 298 && id <= 317 // armors
|| id == 346 // fishing rod
|| id == 359 // shears
|| id == 398 // carrot on a stick
|| id == 442 // shield
|| id == 443; // elytra
}
private static void flowerPotSpecialTreatment(UserConnection user, int blockState, Position position) throws Exception {
if (FlowerPotHandler.isFlowah(blockState)) {
BackwardsBlockEntityProvider beProvider = Via.getManager().getProviders().get(BackwardsBlockEntityProvider.class);
CompoundTag nbt = beProvider.transform(user, position, "minecraft:flower_pot");
private void handleEnchantmentClient(Item item) {
PacketWrapper wrapper = new PacketWrapper(0x09, null, user);
wrapper.write(Type.POSITION, position);
wrapper.write(Type.UNSIGNED_BYTE, (short) 5);
wrapper.write(Type.NBT, nbt);
// TODO Why does this not work?
wrapper.send(Protocol1_12_2To1_13.class, true);
}
}
}

Datei anzeigen

@ -18,6 +18,8 @@ import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.platform.providers.Provider;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.IntTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -72,6 +74,23 @@ public class BackwardsBlockEntityProvider implements Provider {
return handler.transform(user, storage.get(position), tag);
}
/**
* Transform blocks to block entities!
*
* @param user The user
* @param position The position of the block entity
* @param id The block entity id
*/
public CompoundTag transform(UserConnection user, Position position, String id) throws Exception {
CompoundTag tag = new CompoundTag("");
tag.put(new StringTag("id", id));
tag.put(new IntTag("x", Math.toIntExact(position.getX())));
tag.put(new IntTag("y", Math.toIntExact(position.getY())));
tag.put(new IntTag("z", Math.toIntExact(position.getZ())));
return this.transform(user, position, tag);
}
public interface BackwardsBlockEntityHandler {
CompoundTag transform(UserConnection user, int blockId, CompoundTag tag);
}