Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-12-27 16:40:12 +01:00
Implement basic block entity interface & handle beds
Dieser Commit ist enthalten in:
Ursprung
404dce4a32
Commit
97b81cf782
@ -19,8 +19,11 @@ import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.BlockItemPack
|
|||||||
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.EntityPackets1_13;
|
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.EntityPackets1_13;
|
||||||
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.PlayerPacket1_13;
|
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.PlayerPacket1_13;
|
||||||
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.SoundPackets1_13;
|
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.SoundPackets1_13;
|
||||||
|
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.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
|
import us.myles.ViaVersion.api.platform.providers.ViaProviders;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
@ -44,7 +47,6 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol {
|
|||||||
|
|
||||||
|
|
||||||
out(State.PLAY, 0x07, 0x07, cancel()); // Statistics TODO MODIFIED
|
out(State.PLAY, 0x07, 0x07, cancel()); // Statistics TODO MODIFIED
|
||||||
out(State.PLAY, 0x09, 0x09, cancel()); // Update Block Entity TODO MODIFIED
|
|
||||||
out(State.PLAY, 0x0E, 0x0F); // Chat Message (clientbound)
|
out(State.PLAY, 0x0E, 0x0F); // Chat Message (clientbound)
|
||||||
out(State.PLAY, 0x11, -1, cancel()); // Declare Commands TODO NEW
|
out(State.PLAY, 0x11, -1, cancel()); // Declare Commands TODO NEW
|
||||||
out(State.PLAY, 0x12, 0x11); // Confirm Transaction (clientbound)
|
out(State.PLAY, 0x12, 0x11); // Confirm Transaction (clientbound)
|
||||||
@ -142,6 +144,15 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol {
|
|||||||
|
|
||||||
// Init protocol in EntityTracker
|
// Init protocol in EntityTracker
|
||||||
user.get(EntityTracker.class).initProtocol(this);
|
user.get(EntityTracker.class).initProtocol(this);
|
||||||
|
|
||||||
|
// Register Block Storage
|
||||||
|
if (!user.has(BackwardsBlockStorage.class))
|
||||||
|
user.put(new BackwardsBlockStorage(user));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void register(ViaProviders providers) {
|
||||||
|
providers.register(BackwardsBlockEntityProvider.class, new BackwardsBlockEntityProvider());
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacketRemapper cancel() {
|
public PacketRemapper cancel() {
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Matsv
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers;
|
||||||
|
|
||||||
|
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
|
||||||
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
|
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||||
|
import us.myles.viaversion.libs.opennbt.tag.builtin.IntTag;
|
||||||
|
|
||||||
|
public class BedHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
|
||||||
|
int offset = blockId - 748;
|
||||||
|
int color = offset >> 4;
|
||||||
|
|
||||||
|
tag.put(new IntTag("color", color));
|
||||||
|
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
}
|
@ -10,12 +10,15 @@
|
|||||||
|
|
||||||
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets;
|
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets;
|
||||||
|
|
||||||
import nl.matsv.viabackwards.api.rewriters.BlockItemRewriter;
|
import nl.matsv.viabackwards.api.rewriters.Rewriter;
|
||||||
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
|
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
|
||||||
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.BackwardsMappings;
|
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.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.minecraft.BlockChangeRecord;
|
import us.myles.ViaVersion.api.minecraft.BlockChangeRecord;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.Position;
|
||||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
||||||
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
||||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||||
@ -28,45 +31,119 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPacke
|
|||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type;
|
||||||
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;
|
||||||
|
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||||
|
|
||||||
|
public class BlockItemPackets1_13 extends Rewriter<Protocol1_12_2To1_13> {
|
||||||
|
public static int toOldId(int oldId) {
|
||||||
|
if (oldId < 0) {
|
||||||
|
oldId = 0; // Some plugins use negative numbers to clear blocks, remap them to air.
|
||||||
|
}
|
||||||
|
int newId = BackwardsMappings.blockMappings.getNewBlock(oldId);
|
||||||
|
if (newId != -1)
|
||||||
|
return newId;
|
||||||
|
|
||||||
|
Via.getPlatform().getLogger().warning("Missing block completely " + oldId);
|
||||||
|
// Default stone
|
||||||
|
return 1 << 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Basic translation for now. TODO remap new items; should probably use BlockItemRewriter#handleItemToClient/Server, but that needs some rewriting
|
||||||
|
public static void toClient(Item item) {
|
||||||
|
InventoryPackets.toServer(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void toServer(Item item) {
|
||||||
|
InventoryPackets.toClient(item);
|
||||||
|
}
|
||||||
|
|
||||||
public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13> {
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerPackets(Protocol1_12_2To1_13 protocol) {
|
protected void registerPackets(Protocol1_12_2To1_13 protocol) {
|
||||||
|
|
||||||
//Block Change
|
// Update Block Entity
|
||||||
protocol.out(State.PLAY, 0x0B, 0x0B, new PacketRemapper() {
|
protocol.out(State.PLAY, 0x09, 0x09, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
map(Type.POSITION);
|
map(Type.POSITION); // 0 - Position
|
||||||
handler(new PacketHandler() {
|
map(Type.UNSIGNED_BYTE); // 1 - Action
|
||||||
@Override
|
map(Type.NBT); // 2 - NBT Data
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
|
||||||
int blockState = wrapper.read(Type.VAR_INT);
|
|
||||||
wrapper.write(Type.VAR_INT, toOldId(blockState));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//Multi Block Change
|
|
||||||
protocol.out(State.PLAY, 0x0F, 0x10, new PacketRemapper() {
|
|
||||||
@Override
|
|
||||||
public void registerMap() {
|
|
||||||
map(Type.INT);
|
|
||||||
map(Type.INT);
|
|
||||||
map(Type.BLOCK_CHANGE_RECORD_ARRAY);
|
|
||||||
handler(new PacketHandler() {
|
handler(new PacketHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) {
|
BackwardsBlockEntityProvider provider = Via.getManager().getProviders().get(BackwardsBlockEntityProvider.class);
|
||||||
record.setBlockId(toOldId(record.getBlockId()));
|
|
||||||
|
switch (wrapper.get(Type.UNSIGNED_BYTE, 0)) {
|
||||||
|
case 11:
|
||||||
|
wrapper.set(Type.NBT, 0,
|
||||||
|
provider.transform(
|
||||||
|
wrapper.user(),
|
||||||
|
wrapper.get(Type.POSITION, 0),
|
||||||
|
wrapper.get(Type.NBT, 0)
|
||||||
|
));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
wrapper.cancel(); // TODO CONFIRM EVERYTHING WORKING BEFORE REMOVING THIS
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//Windows Items
|
// Block Change
|
||||||
|
protocol.out(State.PLAY, 0x0B, 0x0B, new PacketRemapper() {
|
||||||
|
@Override
|
||||||
|
public void registerMap() {
|
||||||
|
map(Type.POSITION); // 0 - Position
|
||||||
|
|
||||||
|
handler(new PacketHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
|
int blockState = wrapper.read(Type.VAR_INT);
|
||||||
|
|
||||||
|
// Store blocks for
|
||||||
|
BackwardsBlockStorage storage = wrapper.user().get(BackwardsBlockStorage.class);
|
||||||
|
storage.checkAndStore(wrapper.get(Type.POSITION, 0), blockState);
|
||||||
|
|
||||||
|
wrapper.write(Type.VAR_INT, toOldId(blockState));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Multi Block Change
|
||||||
|
protocol.out(State.PLAY, 0x0F, 0x10, new PacketRemapper() {
|
||||||
|
@Override
|
||||||
|
public void registerMap() {
|
||||||
|
map(Type.INT); // 0 - Chunk X
|
||||||
|
map(Type.INT); // 1 - Chunk Z
|
||||||
|
map(Type.BLOCK_CHANGE_RECORD_ARRAY);
|
||||||
|
handler(new PacketHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
|
BackwardsBlockStorage storage = wrapper.user().get(BackwardsBlockStorage.class);
|
||||||
|
|
||||||
|
for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) {
|
||||||
|
int chunkX = wrapper.get(Type.INT, 0);
|
||||||
|
int chunkZ = wrapper.get(Type.INT, 1);
|
||||||
|
int block = record.getBlockId();
|
||||||
|
Position position = new Position(
|
||||||
|
(long) (record.getHorizontal() >> 4 & 15) + (chunkX * 16),
|
||||||
|
(long) record.getY(),
|
||||||
|
(long) (record.getHorizontal() & 15) + (chunkZ * 16));
|
||||||
|
|
||||||
|
// Store if needed
|
||||||
|
storage.checkAndStore(position, block);
|
||||||
|
|
||||||
|
// Change to old id
|
||||||
|
record.setBlockId(toOldId(block));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Windows Items
|
||||||
protocol.out(State.PLAY, 0x15, 0x14, new PacketRemapper() {
|
protocol.out(State.PLAY, 0x15, 0x14, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
@ -84,7 +161,7 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//Set Slot
|
// Set Slot
|
||||||
protocol.out(State.PLAY, 0x17, 0x16, new PacketRemapper() {
|
protocol.out(State.PLAY, 0x17, 0x16, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
@ -114,6 +191,35 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
|
|||||||
Chunk1_13Type type = new Chunk1_13Type(clientWorld);
|
Chunk1_13Type type = new Chunk1_13Type(clientWorld);
|
||||||
Chunk chunk = wrapper.read(type);
|
Chunk chunk = wrapper.read(type);
|
||||||
|
|
||||||
|
|
||||||
|
// Handle Block Entities before block rewrite
|
||||||
|
BackwardsBlockEntityProvider provider = Via.getManager().getProviders().get(BackwardsBlockEntityProvider.class);
|
||||||
|
BackwardsBlockStorage storage = wrapper.user().get(BackwardsBlockStorage.class);
|
||||||
|
for (CompoundTag tag : chunk.getBlockEntities()) {
|
||||||
|
if (!tag.contains("id"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
String id = (String) tag.get("id").getValue();
|
||||||
|
|
||||||
|
// Ignore if we don't handle it
|
||||||
|
if (!provider.isHandled(id))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int sectionIndex = ((int) tag.get("y").getValue()) >> 4;
|
||||||
|
ChunkSection section = chunk.getSections()[sectionIndex];
|
||||||
|
|
||||||
|
int x = (int) tag.get("x").getValue();
|
||||||
|
int y = (int) tag.get("y").getValue();
|
||||||
|
int z = (int) tag.get("z").getValue();
|
||||||
|
Position position = new Position((long) x, (long) y, (long) z);
|
||||||
|
|
||||||
|
int block = section.getFlatBlock(x & 0xF, y & 0xF, z & 0xF);
|
||||||
|
storage.checkAndStore(position, block);
|
||||||
|
|
||||||
|
provider.transform(wrapper.user(), position, tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rewrite new blocks to old blocks
|
||||||
for (int i = 0; i < chunk.getSections().length; i++) {
|
for (int i = 0; i < chunk.getSections().length; i++) {
|
||||||
ChunkSection section = chunk.getSections()[i];
|
ChunkSection section = chunk.getSections()[i];
|
||||||
if (section == null) {
|
if (section == null) {
|
||||||
@ -135,7 +241,6 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
chunk.getBlockEntities().clear();
|
|
||||||
wrapper.write(type_old, chunk);
|
wrapper.write(type_old, chunk);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -143,7 +248,7 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
//Effect
|
// Effect
|
||||||
protocol.out(State.PLAY, 0x23, 0x21, new PacketRemapper() {
|
protocol.out(State.PLAY, 0x23, 0x21, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
@ -168,7 +273,7 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//Map
|
// Map
|
||||||
protocol.out(State.PLAY, 0x26, 0x24, new PacketRemapper() {
|
protocol.out(State.PLAY, 0x26, 0x24, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
@ -197,7 +302,7 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//Entity Equipment
|
// Entity Equipment
|
||||||
protocol.out(State.PLAY, 0x42, 0x3F, new PacketRemapper() {
|
protocol.out(State.PLAY, 0x42, 0x3F, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
@ -215,7 +320,7 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
//Set Creative Slot
|
// Set Creative Slot
|
||||||
protocol.in(State.PLAY, 0x24, 0x1B, new PacketRemapper() {
|
protocol.in(State.PLAY, 0x24, 0x1B, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
@ -231,7 +336,7 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//Click Window
|
// Click Window
|
||||||
protocol.in(State.PLAY, 0x08, 0x07, new PacketRemapper() {
|
protocol.in(State.PLAY, 0x08, 0x07, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
@ -252,27 +357,6 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int toOldId(int oldId) {
|
|
||||||
if (oldId < 0) {
|
|
||||||
oldId = 0; // Some plugins use negative numbers to clear blocks, remap them to air.
|
|
||||||
}
|
|
||||||
int newId = BackwardsMappings.blockMappings.getNewBlock(oldId);
|
|
||||||
if (newId != -1)
|
|
||||||
return newId;
|
|
||||||
|
|
||||||
Via.getPlatform().getLogger().warning("Missing block completely " + oldId);
|
|
||||||
// Default stone
|
|
||||||
return 1 << 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Basic translation for now. TODO remap new items; should probably use BlockItemRewriter#handleItemToClient/Server, but that needs some rewriting
|
|
||||||
public static void toClient(Item item) {
|
|
||||||
InventoryPackets.toServer(item);
|
|
||||||
}
|
|
||||||
public static void toServer(Item item) {
|
|
||||||
InventoryPackets.toClient(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerRewrites() {
|
protected void registerRewrites() {
|
||||||
|
|
||||||
|
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Matsv
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers;
|
||||||
|
|
||||||
|
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.BedHandler;
|
||||||
|
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage;
|
||||||
|
import us.myles.ViaVersion.api.Via;
|
||||||
|
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 java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class BackwardsBlockEntityProvider implements Provider {
|
||||||
|
private final Map<String, BackwardsBlockEntityProvider.BackwardsBlockEntityHandler> handlers = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public BackwardsBlockEntityProvider() {
|
||||||
|
// handlers.put("minecraft:flower_pot", );
|
||||||
|
handlers.put("minecraft:bed", new BedHandler());
|
||||||
|
// handlers.put("minecraft:banner", );
|
||||||
|
// handlers.put("minecraft:skull", );
|
||||||
|
// handlers.put("minecraft:mob_spawner", );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a block entity handler is present
|
||||||
|
*
|
||||||
|
* @param key Id of the NBT data ex: minecraft:bed
|
||||||
|
* @return true if present
|
||||||
|
*/
|
||||||
|
public boolean isHandled(String key) {
|
||||||
|
return handlers.containsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transform blocks to block entities!
|
||||||
|
*
|
||||||
|
* @param user The user
|
||||||
|
* @param position The position of the block entity
|
||||||
|
* @param tag The block entity tag
|
||||||
|
*/
|
||||||
|
public CompoundTag transform(UserConnection user, Position position, CompoundTag tag) throws Exception {
|
||||||
|
String id = (String) tag.get("id").getValue();
|
||||||
|
BackwardsBlockEntityHandler handler = handlers.get(id);
|
||||||
|
if (handler == null) {
|
||||||
|
if (Via.getManager().isDebug()) {
|
||||||
|
Via.getPlatform().getLogger().warning("Unhandled BlockEntity " + id + " full tag: " + tag);
|
||||||
|
}
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
BackwardsBlockStorage storage = user.get(BackwardsBlockStorage.class);
|
||||||
|
|
||||||
|
if (!storage.contains(position)) {
|
||||||
|
if (Via.getManager().isDebug()) {
|
||||||
|
Via.getPlatform().getLogger().warning("Handled BlockEntity does not have a stored block :( " + id + " full tag: " + tag);
|
||||||
|
}
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
return handler.transform(user, storage.get(position), tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface BackwardsBlockEntityHandler {
|
||||||
|
CompoundTag transform(UserConnection user, int blockId, CompoundTag tag);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Matsv
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import us.myles.ViaVersion.api.data.StoredObject;
|
||||||
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.Position;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class BackwardsBlockStorage extends StoredObject {
|
||||||
|
// This BlockStorage is very exclusive (;
|
||||||
|
private static final Set<Integer> whitelist = Sets.newConcurrentHashSet();
|
||||||
|
|
||||||
|
static {
|
||||||
|
// Flower pots
|
||||||
|
// whitelist.add(5266);
|
||||||
|
|
||||||
|
// Add those beds
|
||||||
|
for (int i = 0; i < (16 * 16); i++)
|
||||||
|
whitelist.add(748 + i);
|
||||||
|
|
||||||
|
// Add the white banners
|
||||||
|
// for (int i = 0; i < 20; i++)
|
||||||
|
// whitelist.add(6854 + i);
|
||||||
|
//
|
||||||
|
// Add the white wall banners
|
||||||
|
// for (int i = 0; i < 4; i++) {
|
||||||
|
// whitelist.add(7110 + i);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Skeleton skulls
|
||||||
|
// for (int i = 0; i < 5; i++)
|
||||||
|
// whitelist.add(5447 + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<Position, Integer> blocks = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public BackwardsBlockStorage(UserConnection user) {
|
||||||
|
super(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkAndStore(Position position, int block) {
|
||||||
|
if (!whitelist.contains(block)) {
|
||||||
|
// Remove if not whitelisted
|
||||||
|
if (blocks.containsKey(position))
|
||||||
|
blocks.remove(position);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
blocks.put(position, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWelcome(int block) {
|
||||||
|
return whitelist.contains(block);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(Position position) {
|
||||||
|
return blocks.containsKey(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int get(Position position) {
|
||||||
|
return blocks.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int remove(Position position) {
|
||||||
|
return blocks.remove(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -20,7 +20,7 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class Protocol1_11_1To1_12 extends BackwardsProtocol {
|
public class Protocol1_11_1To1_12 extends BackwardsProtocol {
|
||||||
// TODO store all rewriters and make them easy accessible?
|
// TODO checkAndStore all rewriters and make them easy accessible?
|
||||||
private EntityPackets1_12 entityPackets;
|
private EntityPackets1_12 entityPackets;
|
||||||
private BlockItemPackets1_12 blockItemPackets;
|
private BlockItemPackets1_12 blockItemPackets;
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren