use of com.bergerkiller.bukkit.common.wrappers.BlockRenderOptions in project BKCommonLib by bergerhealer.
the class ConditionalDeserializer method deserialize.
@Override
public BlockModelState.Condition deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
BlockModelState.Condition result = new BlockModelState.Condition();
result.mode = BlockModelState.Condition.Mode.AND;
result.conditions = new ArrayList<BlockModelState.Condition>(1);
if (jsonElement.isJsonPrimitive()) {
// Options stored in a single String token
Map<String, String> options = new BlockRenderOptions(BlockData.AIR, jsonElement.getAsString());
for (Map.Entry<String, String> option : options.entrySet()) {
result.conditions.add(createSelfCondition(option.getKey(), option.getValue()));
}
} else {
// Handle operator types in the condition structure
JsonObject obj = jsonElement.getAsJsonObject();
for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
// Start a new sub-condition, defaulting to mode SELF
BlockModelState.Condition subCondition = new BlockModelState.Condition();
subCondition.mode = BlockModelState.Condition.Mode.SELF;
for (BlockModelState.Condition.Mode mode : BlockModelState.Condition.Mode.values()) {
if (entry.getKey().equals(mode.name())) {
subCondition.mode = mode;
break;
}
}
if (subCondition.mode == BlockModelState.Condition.Mode.SELF) {
// Self: store key:value pair
subCondition = createSelfCondition(entry.getKey(), entry.getValue().getAsString());
} else {
// Create a sub-tree with this operator mode
if (entry.getValue().isJsonArray()) {
// Array of Object conditions
JsonArray condArr = entry.getValue().getAsJsonArray();
subCondition.conditions = new ArrayList<BlockModelState.Condition>(condArr.size());
for (JsonElement condElem : condArr) {
subCondition.conditions.add(deserialize(condElem, type, jsonDeserializationContext));
}
} else {
// Single Object condition
subCondition.conditions = Arrays.asList(deserialize(entry.getValue(), type, jsonDeserializationContext));
}
}
result.conditions.add(subCondition);
}
}
// Simplify if only one element
if (result.conditions.size() == 1) {
return result.conditions.get(0);
} else {
return result;
}
}
use of com.bergerkiller.bukkit.common.wrappers.BlockRenderOptions in project BKCommonLib by bergerhealer.
the class Pseudo3DImagePanel method paintComponent.
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
MapTexture image = MapTexture.createEmpty(MapModelRenderTest.RES_WIDTH, MapModelRenderTest.RES_HEIGHT);
image.draw(background, 0, 0);
image.setBlendMode(MapBlendMode.OVERLAY);
// new Vector3(-1.0, 1.0, -1.0));
image.setLightOptions(0.0f, 1.0f, new Vector3(-1, 1, -1));
System.out.println("{" + p3.x + ", " + p2.x + ", " + p3.y + "}");
// Draws a 3D quad
float scale = 16.0f;
float yaw = (float) (p1.x - 128);
float pitch = (float) (p1.y - 128);
System.out.println("Yaw=" + yaw + " Pitch=" + pitch);
BlockRenderOptions opt = BlockData.fromMaterialData(Material.RAILS, 5).getDefaultRenderOptions();
opt.put("west", "side");
System.out.println(opt);
ItemStack item = ItemUtil.createItem(Material.COOKED_FISH, 0, 1);
ItemUtil.getMetaTag(item, true).putValue("Unbreakable", true);
// textures.getBlockModel(opt);
Model model = textures.getItemModel(item);
Matrix4x4 transform = new Matrix4x4();
// image.draw(textures.getItemTexture(item, 32, 32), 0, 0);
transform.translate(p0.x, 0.0f, p0.y);
transform.scale(scale);
transform.rotateX(pitch);
transform.rotateY(yaw);
transform.translate(-8, -8, -8);
// image.drawModel(textures.getBlockModel(Material.QUARTZ_BLOCK), transform);
transform.translate(20, 0, 0);
image.drawModel(model, transform);
g.drawImage(image.toJavaImage(), 0, 0, null);
int r = 8;
g.setColor(Color.BLUE);
g.fillOval((int) p0.x - r, (int) p0.y - r, r + r, r + r);
g.fillOval((int) p1.x - r, (int) p1.y - r, r + r, r + r);
g.fillOval((int) p2.x - r, (int) p2.y - r, r + r, r + r);
g.fillOval((int) p3.x - r, (int) p3.y - r, r + r, r + r);
}
use of com.bergerkiller.bukkit.common.wrappers.BlockRenderOptions in project BKCommonLib by bergerhealer.
the class ModelInfoLookup method lookupItemRenderOptions.
public static ItemRenderOptions lookupItemRenderOptions(ItemStack item) {
// Blocks
Material type = (item == null) ? Material.AIR : item.getType();
if (item == null || type.isBlock()) {
BlockRenderOptions blockOpt = BlockData.fromItemStack(item).getDefaultRenderOptions();
return new ItemRenderOptions(item, blockOpt);
}
// Some items, like leather boots, require additional render options passed
ItemRenderOptions options = new ItemRenderOptions(item, "");
if (type == Material.LEATHER_BOOTS || type == Material.LEATHER_CHESTPLATE || type == Material.LEATHER_HELMET || type == Material.LEATHER_LEGGINGS) {
// Check 'display.color' metadata tag for custom colors
// default brown
int color = 5190175;
CommonTagCompound nbt = ItemUtil.getMetaTag(item, false);
if (nbt != null) {
CommonTagCompound display = nbt.getValue("display", CommonTagCompound.class);
if (display != null) {
color = display.getValue("color", color);
}
}
// Convert color to hexadecimal and store it as an option
options.put("layer0tint", String.format("#%06x", color));
}
// Similarly, the liquid inside potion bottles have a color set
if (type == Material.POTION || type.name().equals("LINGERING_POTION") || type.name().equals("SPLASH_POTION")) {
int color = getPotionColor(item.getDurability());
// Check 'CustomPotionColor' metadata tag for custom colors
CommonTagCompound nbt = ItemUtil.getMetaTag(item, false);
if (nbt != null) {
color = nbt.getValue("CustomPotionColor", color);
}
// Convert color to hexadecimal and store it as an option
options.put("layer0tint", String.format("#%06x", color));
}
// damage and damaged properties of weapons, armor and tools
if (ItemUtil.hasDurability(item)) {
boolean unbreakable = false;
CommonTagCompound nbt = ItemUtil.getMetaTag(item, false);
if (nbt != null) {
unbreakable = nbt.getValue("Unbreakable", unbreakable);
}
options.put("damaged", unbreakable ? "0" : "1");
options.put("damage", Double.toString((double) item.getDurability() / (double) (ItemUtil.getMaxDurability(item) + 1)));
}
return options;
}
Aggregations