Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-12-26 08:10:10 +01:00
Fix Spawn eggs
Dieser Commit ist enthalten in:
Ursprung
ff73405d92
Commit
2060a698bd
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* 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.api.entities.blockitem;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import nl.matsv.viabackwards.utils.Block;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||||
|
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public class BlockItemSettings {
|
||||||
|
private final int id;
|
||||||
|
private Item repItem;
|
||||||
|
private Block repBlock;
|
||||||
|
private BlockEntityHandler blockEntityHandler;
|
||||||
|
private ItemHandler itemHandler;
|
||||||
|
|
||||||
|
public BlockItemSettings repItem(Item item) {
|
||||||
|
this.repItem = item;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockItemSettings repBlock(Block block) {
|
||||||
|
this.repBlock = block;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockItemSettings blockEntityHandler(BlockEntityHandler handler) {
|
||||||
|
this.blockEntityHandler = handler;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockItemSettings itemHandler(ItemHandler handler) {
|
||||||
|
this.itemHandler = handler;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasRepItem() {
|
||||||
|
return repItem != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasRepBlock() {
|
||||||
|
return repBlock != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasEntityHandler() {
|
||||||
|
return blockEntityHandler != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasItemTagHandler() {
|
||||||
|
return itemHandler != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface BlockEntityHandler {
|
||||||
|
CompoundTag handleOrNewCompoundTag(int block, CompoundTag tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface ItemHandler {
|
||||||
|
Item handle(Item i);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -95,9 +95,7 @@ public class MetaHandlerSettings {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hasIndex() && metadata.getId() != getFilterIndex())
|
return !(hasIndex() && metadata.getId() != getFilterIndex());
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,12 @@
|
|||||||
|
|
||||||
package nl.matsv.viabackwards.api.rewriters;
|
package nl.matsv.viabackwards.api.rewriters;
|
||||||
|
|
||||||
import lombok.*;
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
import nl.matsv.viabackwards.api.BackwardsProtocol;
|
import nl.matsv.viabackwards.api.BackwardsProtocol;
|
||||||
|
import nl.matsv.viabackwards.api.entities.blockitem.BlockItemSettings;
|
||||||
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.Chunk;
|
||||||
@ -26,40 +30,39 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
|
|
||||||
public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rewriter<T> {
|
public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rewriter<T> {
|
||||||
private static final CompoundTagConverter converter = new CompoundTagConverter();
|
private static final CompoundTagConverter converter = new CompoundTagConverter();
|
||||||
private final Map<Integer, BlockItemData> replacementData = new ConcurrentHashMap<>();
|
private final Map<Integer, BlockItemSettings> replacementData = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
protected void rewriteItem(int oldItem, Item newItem) {
|
protected BlockItemSettings rewrite(int itemId) {
|
||||||
replacementData.put(oldItem, new BlockItemData(oldItem, newItem, null, null));
|
BlockItemSettings settings = new BlockItemSettings(itemId);
|
||||||
|
replacementData.put(itemId, settings);
|
||||||
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void rewriteBlockItem(int oldId, Item newItem, Block newBlock) {
|
protected Item handleItemToClient(Item i) {
|
||||||
rewriteBlockItem(oldId, newItem, newBlock, null);
|
if (i == null)
|
||||||
}
|
|
||||||
|
|
||||||
protected void rewriteBlockItem(int oldId, Item newItem, Block newBlock, BlockEntityHandler handler) {
|
|
||||||
replacementData.put(oldId, new BlockItemData(oldId, newItem, newBlock, handler));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Item handleItemToClient(Item item) {
|
|
||||||
if (item == null)
|
|
||||||
return null;
|
return null;
|
||||||
if (!replacementData.containsKey((int) item.getId()))
|
if (!replacementData.containsKey((int) i.getId()))
|
||||||
return item;
|
return i;
|
||||||
BlockItemData data = replacementData.get((int) item.getId());
|
BlockItemSettings data = replacementData.get((int) i.getId());
|
||||||
if (!data.hasRepItem())
|
|
||||||
return item;
|
|
||||||
|
|
||||||
Item i = ItemUtil.copyItem(data.getRepItem());
|
if (data.hasRepItem()) {
|
||||||
|
i = ItemUtil.copyItem(data.getRepItem());
|
||||||
|
|
||||||
if (i.getTag() == null)
|
if (i.getTag() == null)
|
||||||
i.setTag(new CompoundTag(""));
|
i.setTag(new CompoundTag(""));
|
||||||
i.getTag().put(createViaNBT(item));
|
i.getTag().put(createViaNBT(i));
|
||||||
|
|
||||||
if (item.getTag() != null)
|
if (i.getTag() != null)
|
||||||
for (Tag ai : item.getTag())
|
for (Tag ai : i.getTag())
|
||||||
i.getTag().put(ai);
|
i.getTag().put(ai);
|
||||||
|
i.setAmount(i.getAmount());
|
||||||
|
}
|
||||||
|
if (data.hasItemTagHandler()) {
|
||||||
|
if (!i.getTag().contains("ViaBackwards|" + getProtocolName()))
|
||||||
|
i.getTag().put(createViaNBT(i));
|
||||||
|
data.getItemHandler().handle(i);
|
||||||
|
}
|
||||||
|
|
||||||
i.setAmount(item.getAmount());
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,9 +82,10 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
|
|||||||
item.setData(data);
|
item.setData(data);
|
||||||
item.setAmount(amount);
|
item.setAmount(amount);
|
||||||
item.setTag(converter.convert("", converter.convert(extras)));
|
item.setTag(converter.convert("", converter.convert(extras)));
|
||||||
// Remove data blockEntityHandler
|
// Remove data tag
|
||||||
tag.remove("ViaBackwards|" + getProtocolName());
|
tag.remove("ViaBackwards|" + getProtocolName());
|
||||||
}
|
}
|
||||||
|
System.out.println("TO_SERVER: " + item);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +164,11 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected boolean hasBlockEntityHandler(int block) {
|
protected boolean hasBlockEntityHandler(int block) {
|
||||||
return replacementData.containsKey(block) && replacementData.get(block).hasHandler();
|
return replacementData.containsKey(block) && replacementData.get(block).hasEntityHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean hasItemTagHandler(int block) {
|
||||||
|
return replacementData.containsKey(block) && replacementData.get(block).hasItemTagHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompoundTag createViaNBT(Item i) {
|
private CompoundTag createViaNBT(Item i) {
|
||||||
@ -186,32 +194,6 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
|
|||||||
return getProtocol().getClass().getSimpleName();
|
return getProtocol().getClass().getSimpleName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface BlockEntityHandler {
|
|
||||||
CompoundTag handleOrNewCompoundTag(int block, CompoundTag tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class BlockItemData {
|
|
||||||
private final int id;
|
|
||||||
private final Item repItem;
|
|
||||||
private final Block repBlock;
|
|
||||||
private final BlockEntityHandler blockEntityHandler;
|
|
||||||
|
|
||||||
public boolean hasRepItem() {
|
|
||||||
return repItem != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasRepBlock() {
|
|
||||||
return repBlock != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasHandler() {
|
|
||||||
return blockEntityHandler != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@ToString
|
@ToString
|
||||||
|
@ -122,26 +122,13 @@ public class EntityTypeNames {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public static void toClientItem(Item item) {
|
public static void toClientItem(Item item) {
|
||||||
if (hasEntityTag(item)) {
|
if (hasEntityTag(item)) {
|
||||||
CompoundTag entityTag = item.getBlockEntityHandler().get("EntityTag");
|
CompoundTag entityTag = item.getTag().get("EntityTag");
|
||||||
toClient(entityTag);
|
toClient(entityTag);
|
||||||
}
|
}
|
||||||
if (item != null && item.getAmount() <= 0) item.setAmount((byte) 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void toServerItem(Item item) {
|
|
||||||
if (hasEntityTag(item)) {
|
|
||||||
CompoundTag entityTag = item.getBlockEntityHandler().get("EntityTag");
|
|
||||||
if (entityTag.get("id") instanceof StringTag) {
|
|
||||||
StringTag id = entityTag.get("id");
|
|
||||||
if (newToOldNames.inverse().containsKey(id.getValue())) {
|
|
||||||
id.setValue(newToOldNames.inverse().get(id.getValue()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
private static boolean hasEntityTag(Item item) {
|
private static boolean hasEntityTag(Item item) {
|
||||||
if (item != null && item.getId() == 383) { // Monster Egg
|
if (item != null && item.getId() == 383) { // Monster Egg
|
||||||
CompoundTag tag = item.getTag();
|
CompoundTag tag = item.getTag();
|
||||||
|
@ -260,21 +260,27 @@ public class BlockItemPackets extends BlockItemRewriter<Protocol1_10To1_11> {
|
|||||||
protected void registerRewrites() {
|
protected void registerRewrites() {
|
||||||
// ShulkerBoxes to chests
|
// ShulkerBoxes to chests
|
||||||
for (int i = 219; i < 235; i++)
|
for (int i = 219; i < 235; i++)
|
||||||
rewriteBlockItem(i,
|
rewrite(i)
|
||||||
new Item((short) 54, (byte) 1, (short) 0, getNamedTag("1.11 Shulker Box (Color #" + (i - 219) + ")")),
|
.repItem(new Item((short) 54, (byte) 1, (short) 0, getNamedTag("1.11 Shulker Box (Color #" + (i - 219) + ")")))
|
||||||
new Block(54, 1));
|
.repBlock(new Block(54, 1));
|
||||||
|
|
||||||
// Observer to Dispenser TODO facing position?
|
// Observer to Dispenser TODO facing position?
|
||||||
rewriteBlockItem(218, new Item((short) 23, (byte) 1, (short) 0, getNamedTag("1.11 Observer")), new Block(23, 0));
|
rewrite(218).repItem(new Item((short) 23, (byte) 1, (short) 0, getNamedTag("1.11 Observer"))).repBlock(new Block(23, 0));
|
||||||
|
|
||||||
// Handle spawner block entity
|
// Handle spawner block entity
|
||||||
rewriteBlockItem(52, null, null, (b, tag) -> {
|
rewrite(52).blockEntityHandler((b, tag) -> {
|
||||||
EntityTypeNames.toClientSpawner(tag);
|
EntityTypeNames.toClientSpawner(tag);
|
||||||
return tag;
|
return tag;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Rewrite spawn eggs TODO maybe intercept / handle server for creative instead of ViaBackwards NBT
|
||||||
|
rewrite(383).itemHandler((i) -> {
|
||||||
|
EntityTypeNames.toClientItem(i);
|
||||||
|
return i;
|
||||||
|
});
|
||||||
|
|
||||||
// Totem of Undying to Dead Bush
|
// Totem of Undying to Dead Bush
|
||||||
rewriteItem(449, new Item((short) 32, (byte) 1, (short) 0, getNamedTag("1.11 Totem of Undying")));
|
rewrite(449).repItem(new Item((short) 32, (byte) 1, (short) 0, getNamedTag("1.11 Totem of Undying")));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,6 +151,6 @@ public class ItemPackets extends BlockItemRewriter<Protocol1_11To1_11_1> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerRewrites() {
|
protected void registerRewrites() {
|
||||||
rewriteItem(452, new Item((short) 265, (byte) 1, (short) 0, getNamedTag("1.11.2 Iron Nugget")));
|
rewrite(452).repItem(new Item((short) 265, (byte) 1, (short) 0, getNamedTag("1.11.2 Iron Nugget")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -232,11 +232,11 @@ public class BlockItemPackets extends BlockItemRewriter<Protocol1_9_4To1_10> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerRewrites() {
|
protected void registerRewrites() {
|
||||||
rewriteItem(255, new Item((short) 166, (byte) 1, (short) 0, getNamedTag("1.10 Structure Block"))); // Structure block only item since the structure block is in 1.9
|
rewrite(255).repItem(new Item((short) 166, (byte) 1, (short) 0, getNamedTag("1.10 Structure Block"))); // Structure block only item since the structure block is in 1.9
|
||||||
rewriteBlockItem(217, new Item((short) 287, (byte) 1, (short) 0, getNamedTag("1.10 Structure Void")), new Block(287, 0)); // Structure void to string
|
rewrite(217).repItem(new Item((short) 287, (byte) 1, (short) 0, getNamedTag("1.10 Structure Void"))).repBlock(new Block(287, 0)); // Structure void to string
|
||||||
rewriteBlockItem(213, new Item((short) 159, (byte) 1, (short) 1, getNamedTag("1.10 Magma Block")), new Block(159, 1)); // Magma block to orange clay
|
rewrite(213).repItem(new Item((short) 159, (byte) 1, (short) 1, getNamedTag("1.10 Magma Block"))).repBlock(new Block(159, 1)); // Magma block to orange clay
|
||||||
rewriteBlockItem(214, new Item((short) 159, (byte) 1, (short) 14, getNamedTag("1.10 Nether Ward Block")), new Block(159, 14)); // Nether wart block to red clay
|
rewrite(214).repItem(new Item((short) 159, (byte) 1, (short) 14, getNamedTag("1.10 Nether Ward Block"))).repBlock(new Block(159, 14)); // Nether wart block to red clay
|
||||||
rewriteBlockItem(215, new Item((short) 112, (byte) 1, (short) 0, getNamedTag("1.10 Red Nether Bricks")), new Block(112, 0)); // Red nether brick to nether brick
|
rewrite(215).repItem(new Item((short) 112, (byte) 1, (short) 0, getNamedTag("1.10 Red Nether Bricks"))).repBlock(new Block(112, 0)); // Red nether brick to nether brick
|
||||||
rewriteBlockItem(216, new Item((short) 155, (byte) 1, (short) 0, getNamedTag("1.10 Bone Block")), new Block(155, 0)); // Bone block to quartz
|
rewrite(216).repItem(new Item((short) 155, (byte) 1, (short) 0, getNamedTag("1.10 Bone Block"))).repBlock(new Block(155, 0)); // Bone block to quartz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren