Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-12-26 16:12:43 +01:00
Implement a color variable for item names
Dieser Commit ist enthalten in:
Ursprung
961991a316
Commit
9ed4a15b32
@ -16,6 +16,7 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import nl.matsv.viabackwards.api.BackwardsProtocol;
|
||||
import nl.matsv.viabackwards.api.entities.blockitem.BlockItemSettings;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data.BlockColors;
|
||||
import nl.matsv.viabackwards.utils.Block;
|
||||
import nl.matsv.viabackwards.utils.ItemUtil;
|
||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
||||
@ -53,6 +54,17 @@ public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rew
|
||||
i.setTag(new CompoundTag(""));
|
||||
i.getTag().put(createViaNBT(original));
|
||||
|
||||
// Handle colors
|
||||
if (i.getTag().contains("display")) {
|
||||
CompoundTag tag = i.getTag().get("display");
|
||||
if (tag.contains("Name")) {
|
||||
String value = (String) tag.get("Name").getValue();
|
||||
|
||||
tag.put(new StringTag("Name",
|
||||
value.replaceAll("%viabackwards_color%", BlockColors.get((int) original.getData()))));
|
||||
}
|
||||
}
|
||||
|
||||
i.setAmount(original.getAmount());
|
||||
// Keep original data when -1
|
||||
if (i.getData() == -1)
|
||||
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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_12to1_11_1.data;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class BlockColors {
|
||||
private static Map<Integer, String> colors = new ConcurrentHashMap<>();
|
||||
private static int count = 0;
|
||||
|
||||
static {
|
||||
add("White");
|
||||
add("Orange");
|
||||
add("Magenta");
|
||||
add("Light Blue");
|
||||
add("Yellow");
|
||||
add("Lime");
|
||||
add("Pink");
|
||||
add("Gray");
|
||||
add("Light Gray");
|
||||
add("Cyan");
|
||||
add("Purple");
|
||||
add("Blue");
|
||||
add("Brown");
|
||||
add("Green");
|
||||
add("Red");
|
||||
add("Black");
|
||||
}
|
||||
|
||||
private static void add(String value) {
|
||||
colors.put(count++, value);
|
||||
}
|
||||
|
||||
public static boolean has(Integer key) {
|
||||
return colors.containsKey(key);
|
||||
}
|
||||
|
||||
public static String get(Integer key) {
|
||||
return colors.get(key);
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ package nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.packets;
|
||||
|
||||
import nl.matsv.viabackwards.api.rewriters.BlockItemRewriter;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.Protocol1_11_1To1_12;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data.BlockColors;
|
||||
import nl.matsv.viabackwards.utils.Block;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
@ -269,23 +270,26 @@ public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12
|
||||
protected void registerRewrites() {
|
||||
// Concrete -> Stained clay? (Also got a new name Terracota?)
|
||||
rewrite(251)
|
||||
.repItem(new Item((short) 159, (byte) 1, (short) -1, getNamedTag("1.12 Concrete")))
|
||||
.repBlock(new Block(159, -1)); // TODO color provided by name
|
||||
.repItem(new Item((short) 159, (byte) 1, (short) -1, getNamedTag("1.12 %viabackwards_color% Concrete")))
|
||||
.repBlock(new Block(159, -1));
|
||||
|
||||
// Concrete Powder -> Wool
|
||||
rewrite(252)
|
||||
.repItem(new Item((short) 35, (byte) 1, (short) -1, getNamedTag("1.12 Concrete Powder")))
|
||||
.repBlock(new Block(35, -1)); // TODO color provided by name
|
||||
.repItem(new Item((short) 35, (byte) 1, (short) -1, getNamedTag("1.12 %viabackwards_color% Concrete Powder")))
|
||||
.repBlock(new Block(35, -1));
|
||||
|
||||
// Knowledge book -> book
|
||||
rewrite(453)
|
||||
.repItem(new Item((short) 340, (byte) 1, (short) 0, getNamedTag("1.12 Knowledge Book"))); // TODO glow
|
||||
.repItem(new Item((short) 340, (byte) 1, (short) 0, getNamedTag("1.12 %viabackwards_color% Knowledge Book (Color: #%viabackwards_color%)"))); // TODO glow
|
||||
|
||||
// Glazed Terracotta -> Stained Clay
|
||||
for (int i = 235; i < 251; i++) {
|
||||
rewrite(i).repItem(new Item((short) 159, (byte) 1, (short) (i - 235), getNamedTag("1.12 Glazed Terracotta")))
|
||||
.repBlock(new Block(159, (i - 235))); // TODO color provided by name
|
||||
rewrite(i).repItem(new Item((short) 159, (byte) 1, (short) (i - 235), getNamedTag("1.12 " + BlockColors.get(i - 235) + " Glazed Terracotta")))
|
||||
.repBlock(new Block(159, (i - 235)));
|
||||
}
|
||||
|
||||
// Handle beds
|
||||
rewrite(355).repItem(new Item((short) 355, (byte) 1, (short) 0, getNamedTag("1.12 %viabackwards_color% Bed")));
|
||||
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren