use of org.bukkit.block.BlockFace in project BKCommonLib by bergerhealer.
the class BlockFaceSetTest method testByBlockFace.
@Test
public void testByBlockFace() {
for (BlockFace face : FaceUtil.BLOCK_SIDES) {
BlockFaceSet set = BlockFaceSet.of(face);
assertTrue(set.get(face));
for (BlockFace face2 : FaceUtil.BLOCK_SIDES) {
if (face2 != face) {
assertFalse(set.get(face2));
}
}
}
assertEquals(BlockFaceSet.ALL, BlockFaceSet.of(FaceUtil.BLOCK_SIDES));
assertEquals(BlockFaceSet.NONE, BlockFaceSet.of());
}
use of org.bukkit.block.BlockFace in project BKCommonLib by bergerhealer.
the class IBlockDataToMaterialData method initMaterialDataMap.
// Only called on MC >= 1.13
private static void initMaterialDataMap() {
{
MaterialData materialdata = new MaterialData(MaterialsByName.getMaterial("LEGACY_DOUBLE_STEP"));
for (byte data = 0; data < 8; data++) {
materialdata.setData(data);
IBlockDataHandle iblockdata = MaterialDataToIBlockData.getIBlockData(materialdata);
storeMaterialData(iblockdata.set("waterlogged", true), materialdata);
storeMaterialData(iblockdata.set("waterlogged", false), materialdata);
}
}
storeMaterialDataGen("LEGACY_REDSTONE_COMPARATOR_OFF", 0, 7);
storeMaterialDataGen("LEGACY_REDSTONE_COMPARATOR_ON", 0, 7);
storeMaterialDataGen("LEGACY_PORTAL", 1, 2);
// Store 5 unique kinds of wood types for some materials that don't exist on MC 1.12.2, and thus have no legacy type
// A littly hacky, because MaterialData should only use legacy materials, but in this instance it can work
// Buttons
{
new CustomMaterialDataBuilder<org.bukkit.material.Button>() {
@Override
public org.bukkit.material.Button create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
return new org.bukkit.material.Button(material_type, legacy_data_value);
}
@Override
public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, org.bukkit.material.Button button) {
iblockdata = iblockdata.set("powered", button.isPowered());
BlockFace facing = button.getFacing();
if (!FaceUtil.isVertical(facing)) {
return Arrays.asList(iblockdata.set("face", "WALL").set("facing", facing));
}
iblockdata = iblockdata.set("face", (facing == BlockFace.UP) ? "FLOOR" : "CEILING");
return Arrays.asList(iblockdata.set("facing", BlockFace.NORTH), iblockdata.set("facing", BlockFace.EAST), iblockdata.set("facing", BlockFace.SOUTH), iblockdata.set("facing", BlockFace.WEST));
}
}.setTypes("JUNGLE_BUTTON", "SPRUCE_BUTTON", "ACACIA_BUTTON", "BIRCH_BUTTON", "DARK_OAK_BUTTON", "OAK_BUTTON", "STONE_BUTTON").addTypesIf(Common.evaluateMCVersion(">=", "1.16"), "CRIMSON_BUTTON", "WARPED_BUTTON", "POLISHED_BLACKSTONE_BUTTON").addTypesIf(Common.evaluateMCVersion(">=", "1.17"), "POLISHED_BLACKSTONE_BUTTON").setDataValues(0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13).build();
}
// Levers
{
new CustomMaterialDataBuilder<org.bukkit.material.Lever>() {
@Override
public org.bukkit.material.Lever create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
return new org.bukkit.material.Lever(material_type, legacy_data_value);
}
@Override
public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, org.bukkit.material.Lever button) {
iblockdata = iblockdata.set("powered", button.isPowered());
BlockFace attached = button.getAttachedFace();
if (attached == BlockFace.UP) {
// Attached to the ceiling
// Facing controls what direction the lever points
// However, legacy only supports ambiguous {north/south} and {east/west}
BlockFace facing = ((button.getData() & 0x7) == 0x7) ? BlockFace.NORTH : BlockFace.EAST;
iblockdata = iblockdata.set("face", "ceiling");
return Arrays.asList(iblockdata.set("facing", facing), iblockdata.set("facing", facing.getOppositeFace()));
} else if (attached == BlockFace.DOWN) {
// Attached to the floor
// Facing controls what direction the lever points
// However, legacy only supports ambiguous {north/south} and {east/west}
BlockFace facing = ((button.getData() & 0x7) == 5) ? BlockFace.NORTH : BlockFace.EAST;
iblockdata = iblockdata.set("face", "floor");
return Arrays.asList(iblockdata.set("facing", facing), iblockdata.set("facing", facing.getOppositeFace()));
} else {
// Attached to a wall, facing = orientation on block
iblockdata = iblockdata.set("face", "wall");
iblockdata = iblockdata.set("facing", button.getFacing());
return Collections.singletonList(iblockdata);
}
}
}.setTypes("LEVER").setDataValues(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).build();
}
// Pressureplates
{
new CustomMaterialDataBuilder<org.bukkit.material.PressurePlate>() {
@Override
public org.bukkit.material.PressurePlate create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
return new org.bukkit.material.PressurePlate(material_type, legacy_data_value);
}
@Override
public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, org.bukkit.material.PressurePlate plate) {
return Arrays.asList(iblockdata.set("powered", plate.isPressed()));
}
}.setTypes("JUNGLE_PRESSURE_PLATE", "SPRUCE_PRESSURE_PLATE", "ACACIA_PRESSURE_PLATE", "BIRCH_PRESSURE_PLATE", "DARK_OAK_PRESSURE_PLATE").addTypesIf(Common.evaluateMCVersion(">=", "1.16"), "CRIMSON_PRESSURE_PLATE", "WARPED_PRESSURE_PLATE", "POLISHED_BLACKSTONE_PRESSURE_PLATE").addTypesIf(Common.evaluateMCVersion(">=", "1.17"), "POLISHED_BLACKSTONE_PRESSURE_PLATE").setDataValues(0, 1).build();
}
// Burning and not burning furnace (now both the same material, was separate legacy materials)
for (boolean burning : new boolean[] { true, false }) {
new CustomMaterialDataBuilder<org.bukkit.material.Furnace>() {
@Override
public Material toLegacy(Material m) {
return CommonLegacyMaterials.getLegacyMaterial(burning ? "BURNING_FURNACE" : "FURNACE");
}
@Override
public org.bukkit.material.Furnace create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
return new org.bukkit.material.Furnace(toLegacy(material_type), legacy_data_value);
}
@Override
public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, org.bukkit.material.Furnace furnace) {
return Collections.singletonList(iblockdata.set("facing", furnace.getFacing()).set("lit", burning));
}
}.setTypes("FURNACE").setDataValues(2, 3, 4, 5).build();
}
// Wall torch
{
new CustomMaterialDataBuilder<org.bukkit.material.Torch>() {
@Override
public org.bukkit.material.Torch create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
return new org.bukkit.material.Torch(legacy_data_type, legacy_data_value);
}
@Override
public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, org.bukkit.material.Torch torch) {
return Collections.singletonList(iblockdata.set("facing", torch.getFacing()));
}
}.setTypes("WALL_TORCH").setDataValues(1, 2, 3, 4).build();
}
// Wall redstone torch
for (boolean lit : new boolean[] { true, false }) {
new CustomMaterialDataBuilder<org.bukkit.material.RedstoneTorch>() {
@Override
public Material toLegacy(Material m) {
return CommonLegacyMaterials.getLegacyMaterial(lit ? "REDSTONE_TORCH_ON" : "REDSTONE_TORCH_OFF");
}
@Override
public org.bukkit.material.RedstoneTorch create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
return new org.bukkit.material.RedstoneTorch(toLegacy(material_type), legacy_data_value);
}
@Override
public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, org.bukkit.material.RedstoneTorch torch) {
return Collections.singletonList(iblockdata.set("facing", torch.getFacing()).set("lit", lit));
}
}.setTypes("REDSTONE_WALL_TORCH").setDataValues(1, 2, 3, 4).build();
}
// Redstone Wire has north/east/south/west metadata too, which also have to be registered
// Format: minecraft:redstone_wire[east=side,north=none,power=12,south=none,west=none]
{
new CustomMaterialDataBuilder<org.bukkit.material.RedstoneWire>() {
@Override
public org.bukkit.material.RedstoneWire create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
return new org.bukkit.material.RedstoneWire(material_type, legacy_data_value);
}
@Override
public List<IBlockDataHandle> createStates(IBlockDataHandle wire_data, org.bukkit.material.RedstoneWire wire) {
final String[] SIDE_VALUES = { "up", "side", "none" };
ArrayList<IBlockDataHandle> variants = new ArrayList<IBlockDataHandle>(3 * 3 * 3 * 3);
wire_data = wire_data.set("power", wire.getData());
for (String side_north : SIDE_VALUES) {
wire_data = wire_data.set("north", side_north);
for (String side_east : SIDE_VALUES) {
wire_data = wire_data.set("east", side_east);
for (String side_south : SIDE_VALUES) {
wire_data = wire_data.set("south", side_south);
for (String side_west : SIDE_VALUES) {
wire_data = wire_data.set("west", side_west);
variants.add(wire_data);
}
}
}
}
return variants;
}
@Override
public Material fromLegacy(Material legacyMaterial) {
return CommonLegacyMaterials.getMaterial("REDSTONE_WIRE");
}
}.setTypes("LEGACY_REDSTONE_WIRE").setDataValues(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).build();
}
// Chests
{
Material[] legacy_types = CommonLegacyMaterials.getAllByName("LEGACY_CHEST", "LEGACY_ENDER_CHEST", "LEGACY_TRAPPED_CHEST");
Material[] modern_types = CommonLegacyMaterials.getAllByName("CHEST", "ENDER_CHEST", "TRAPPED_CHEST");
for (int n = 0; n < legacy_types.length; n++) {
final Material legacy_type = legacy_types[n];
final Material modern_type = modern_types[n];
final boolean isEnderChest = (n == 1);
new CustomMaterialDataBuilder<org.bukkit.material.DirectionalContainer>() {
@Override
public org.bukkit.material.DirectionalContainer create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
if (isEnderChest) {
org.bukkit.material.EnderChest chest = new org.bukkit.material.EnderChest();
chest.setData(legacy_data_value);
return chest;
} else {
return new org.bukkit.material.Chest(material_type, legacy_data_value);
}
}
@Override
public List<IBlockDataHandle> createStates(IBlockDataHandle chest_data, org.bukkit.material.DirectionalContainer chest) {
chest_data = chest_data.set("facing", chest.getFacing());
return Arrays.asList(chest_data.set("waterlogged", true).set("type", "SINGLE"), chest_data.set("waterlogged", true).set("type", "LEFT"), chest_data.set("waterlogged", true).set("type", "RIGHT"), chest_data.set("waterlogged", false).set("type", "SINGLE"), chest_data.set("waterlogged", false).set("type", "LEFT"), chest_data.set("waterlogged", false).set("type", "RIGHT"));
}
@Override
public Material fromLegacy(Material legacyMaterial) {
return modern_type;
}
@Override
public Material toLegacy(Material material) {
return legacy_type;
}
}.setTypes(legacy_type, modern_type).setDataValues(2, 3, 4, 5).build();
}
}
// Ladder can also be waterlogged since MC 1.15
{
new CustomMaterialDataBuilder<org.bukkit.material.Ladder>() {
@Override
public org.bukkit.material.Ladder create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
return new org.bukkit.material.Ladder(legacy_data_type, legacy_data_value);
}
@Override
public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, org.bukkit.material.Ladder ladder) {
IBlockDataHandle base = iblockdata.set("facing", ladder.getFacing());
return Arrays.asList(base.set("waterlogged", false), base.set("waterlogged", true));
}
}.setTypes("LADDER").setDataValues(2, 3, 4, 5).build();
}
if (CommonCapabilities.HAS_MATERIAL_SIGN_TYPES) {
// LEGACY_WALL_SIGN is broken on 1.14
{
new CustomMaterialDataBuilder<org.bukkit.material.Sign>() {
@Override
public org.bukkit.material.Sign create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
return new CommonSignDataFix(material_type, legacy_data_value, true);
}
@Override
public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, org.bukkit.material.Sign sign) {
IBlockDataHandle base = iblockdata.set("facing", sign.getFacing());
return Arrays.asList(base.set("waterlogged", false), base.set("waterlogged", true));
}
@Override
public Material fromLegacy(Material legacyMaterial) {
return CommonLegacyMaterials.getMaterial("OAK_WALL_SIGN");
}
@Override
public Material toLegacy(Material material) {
return CommonLegacyMaterials.getLegacyMaterial("WALL_SIGN");
}
}.setTypes("ACACIA_WALL_SIGN", "BIRCH_WALL_SIGN", "DARK_OAK_WALL_SIGN", "JUNGLE_WALL_SIGN", "OAK_WALL_SIGN", "SPRUCE_WALL_SIGN", "LEGACY_WALL_SIGN").addTypesIf(CommonBootstrap.evaluateMCVersion(">=", "1.16"), "CRIMSON_WALL_SIGN", "WARPED_WALL_SIGN").setDataValues(2, 3, 4, 5).build();
}
// Register new SIGN_POST types as well
{
new CustomMaterialDataBuilder<org.bukkit.material.Sign>() {
@Override
public org.bukkit.material.Sign create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
return new CommonSignDataFix(material_type, legacy_data_value, false);
}
@Override
public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, org.bukkit.material.Sign sign) {
IBlockDataHandle base = iblockdata.set("rotation", sign.getData());
return Arrays.asList(base.set("waterlogged", false), base.set("waterlogged", true));
}
@Override
public Material fromLegacy(Material legacyMaterial) {
return CommonLegacyMaterials.getMaterial("OAK_SIGN");
}
@Override
public Material toLegacy(Material material) {
return CommonLegacyMaterials.getLegacyMaterial("SIGN_POST");
}
}.setTypes("ACACIA_SIGN", "BIRCH_SIGN", "DARK_OAK_SIGN", "JUNGLE_SIGN", "OAK_SIGN", "SPRUCE_SIGN", "LEGACY_SIGN_POST").addTypesIf(CommonBootstrap.evaluateMCVersion(">=", "1.16"), "CRIMSON_SIGN", "WARPED_SIGN").setDataValues(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).build();
}
} else {
// Fix LEGACY_WALL_SIGN
{
new CustomMaterialDataBuilder<org.bukkit.material.Sign>() {
@Override
public org.bukkit.material.Sign create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
return new CommonSignDataFix(material_type, legacy_data_value, true);
}
@Override
public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, org.bukkit.material.Sign sign) {
IBlockDataHandle base = iblockdata.set("facing", sign.getFacing());
return Arrays.asList(base.set("waterlogged", false), base.set("waterlogged", true));
}
}.setTypes("WALL_SIGN", "LEGACY_WALL_SIGN").setDataValues(2, 3, 4, 5).build();
}
// Fix LEGACY_SIGN_POST
{
new CustomMaterialDataBuilder<org.bukkit.material.Sign>() {
@Override
public org.bukkit.material.Sign create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
return new CommonSignDataFix(material_type, legacy_data_value, false);
}
@Override
public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, org.bukkit.material.Sign sign) {
IBlockDataHandle base = iblockdata.set("rotation", sign.getData());
return Arrays.asList(base.set("waterlogged", false), base.set("waterlogged", true));
}
}.setTypes("SIGN", "LEGACY_SIGN_POST").setDataValues(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).build();
}
}
// Minecraft 1.16 added a Target block, for which we have added a custom material class to support it
if (Common.evaluateMCVersion(">=", "1.16")) {
new CustomMaterialDataBuilder<CommonTargetDataFix>() {
@Override
public CommonTargetDataFix create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
return new CommonTargetDataFix(material_type, legacy_data_value);
}
@Override
public List<IBlockDataHandle> createStates(IBlockDataHandle iblockdata, CommonTargetDataFix target) {
return Collections.singletonList(iblockdata.set("power", Integer.valueOf(target.getData())));
}
}.setTypes("TARGET").setDataValues(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).build();
}
// Rails can be waterlogged since 1.17
if (Common.evaluateMCVersion(">=", "1.17")) {
// Standard rail - which supports curves
new RailMaterialDataBuilder<org.bukkit.material.Rails>("RAIL") {
@Override
public org.bukkit.material.Rails create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
return new org.bukkit.material.Rails(legacy_data_type, legacy_data_value);
}
}.build();
// Special types of rail that do not support curves
new RailMaterialDataBuilder<org.bukkit.material.DetectorRail>("DETECTOR_RAIL") {
@Override
public org.bukkit.material.DetectorRail create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
return new org.bukkit.material.DetectorRail(legacy_data_type, legacy_data_value);
}
@Override
protected IBlockDataHandle apply(IBlockDataHandle iblockdata, org.bukkit.material.DetectorRail rails) {
return iblockdata.set("powered", rails.isPressed());
}
}.build();
new RailMaterialDataBuilder<org.bukkit.material.PoweredRail>("POWERED_RAIL") {
@Override
public org.bukkit.material.PoweredRail create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
return new org.bukkit.material.PoweredRail(legacy_data_type, legacy_data_value);
}
@Override
protected IBlockDataHandle apply(IBlockDataHandle iblockdata, org.bukkit.material.PoweredRail rails) {
return iblockdata.set("powered", rails.isPowered());
}
}.build();
new RailMaterialDataBuilder<org.bukkit.material.PoweredRail>("ACTIVATOR_RAIL") {
@Override
public org.bukkit.material.PoweredRail create(Material material_type, Material legacy_data_type, byte legacy_data_value) {
return new org.bukkit.material.PoweredRail(legacy_data_type, legacy_data_value);
}
@Override
protected IBlockDataHandle apply(IBlockDataHandle iblockdata, org.bukkit.material.PoweredRail rails) {
return iblockdata.set("powered", rails.isPowered());
}
}.build();
}
}
use of org.bukkit.block.BlockFace in project BKCommonLib by bergerhealer.
the class FluidRenderingProvider method createModel.
@Override
public Model createModel(MapResourcePack resources, BlockRenderOptions options) {
// Read all water blocks from options
FluidBlock self = getFluidBlock(options.getBlockData());
FluidBlock neigh_nn = readFluidBlock(options, "neigh_nn");
FluidBlock neigh_ne = readFluidBlock(options, "neigh_ne");
FluidBlock neigh_ee = readFluidBlock(options, "neigh_ee");
FluidBlock neigh_se = readFluidBlock(options, "neigh_se");
FluidBlock neigh_ss = readFluidBlock(options, "neigh_ss");
FluidBlock neigh_sw = readFluidBlock(options, "neigh_sw");
FluidBlock neigh_ww = readFluidBlock(options, "neigh_ww");
FluidBlock neigh_nw = readFluidBlock(options, "neigh_nw");
Model model = new Model();
Model.Element water = new Model.Element();
// Cut out only the first animation block from the texture
// This is the 'side' of the water where no water animations show
MapTexture waterSide = resources.getTexture(this.fluidTexture1);
// waterSide = waterSide.getView(0, 0, waterSide.getWidth(), waterSide.getWidth()).clone();
// Cut out only the first animation block from the texture
// For now, we don't do animations in this renderer.
MapTexture waterTexture = resources.getTexture(this.fluidTexture2);
for (BlockFace blockFace : FaceUtil.BLOCK_SIDES) {
Model.Element.Face face = new Model.Element.Face();
// If blocked by some solid block, show the non-animated 'overlay' texture
// If flowing or top, show the flowing texture
// On the top, we always show the flowing texture
// TODO!
face.texture = FaceUtil.isVertical(blockFace) ? waterTexture : waterSide;
if (this.tint != null) {
face.tintindex = 0;
}
face.buildBlock(options);
water.faces.put(blockFace, face);
}
water.buildQuads();
// Only do this when not flowing down
if (!isFlowingDown(options.getBlockData())) {
Face topFace = water.faces.get(BlockFace.UP);
topFace.quad.p0.y = calcLevel(self, neigh_ww, neigh_nw, neigh_nn);
topFace.quad.p1.y = calcLevel(self, neigh_ss, neigh_sw, neigh_ww);
topFace.quad.p2.y = calcLevel(self, neigh_ee, neigh_se, neigh_ss);
topFace.quad.p3.y = calcLevel(self, neigh_nn, neigh_ne, neigh_ee);
if (this.tint != null) {
topFace.tintindex = 0;
}
topFace.buildBlock(options);
}
model.elements.add(water);
return model;
}
use of org.bukkit.block.BlockFace in project BKCommonLib by bergerhealer.
the class Model method build.
public void build(MapResourcePack resourcePack, RenderOptions options) {
// Mostly for debug, but can be useful elsewhere perhaps?
this.name = options.lookupModelName();
// Build all textures, turning paths into absolute paths
boolean hasChanges;
int loop_limit = 100;
String loop_last_changed = null;
do {
hasChanges = false;
for (Map.Entry<String, String> textureEntry : this.textures.entrySet()) {
String oldTextureValue = textureEntry.getValue();
if (oldTextureValue.startsWith("#")) {
String texture = this.textures.get(oldTextureValue.substring(1));
if (texture != null && !texture.equals(oldTextureValue)) {
textureEntry.setValue(texture);
loop_last_changed = texture;
hasChanges = true;
}
}
}
// Allow for a maximum of 100 loops, then log a cyclical texture loop error
if (--loop_limit <= 0) {
if (loop_last_changed != null) {
Logging.LOGGER_MAPDISPLAY.warning("Texture loop error for model " + this.name + " texture " + loop_last_changed);
}
break;
}
} while (hasChanges);
// This basically creates a small cube for every non-transparent pixel in the texture
if (this.builtinType == BuiltinType.GENERATED) {
this.elements.clear();
MapTexture result = null;
for (int i = 0; ; i++) {
String layerKey = "layer" + i;
String layerTexturePath = this.textures.get(layerKey);
if (layerTexturePath == null) {
break;
}
MapTexture texture = resourcePack.getTexture(layerTexturePath);
// Item-specific layer render colors
texture = applyTint(texture, options.get(layerKey + "tint"));
if (result == null) {
result = texture.clone();
} else {
result.draw(texture, 0, 0);
}
}
if (result != null) {
// We really cannot handle models like 600x600 - bad things really happen...
if (result.getWidth() > 16 || result.getHeight() > 16) {
MapTexture newTexture = MapTexture.createEmpty(16, 16);
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
int px = (x * result.getWidth()) / 16;
int py = (y * result.getHeight()) / 16;
newTexture.writePixel(x, y, result.readPixel(px, py));
}
}
result = newTexture;
}
for (int y = 0; y < result.getHeight(); y++) {
for (int x = 0; x < result.getWidth(); x++) {
byte color = result.readPixel(x, y);
if (color == MapColorPalette.COLOR_TRANSPARENT) {
continue;
}
Element element = new Element();
element.from = new Vector3(x, 0, y);
element.to = new Vector3(element.from.x + 1, element.from.y + 1, element.from.z + 1);
for (BlockFace bface : FaceUtil.BLOCK_SIDES) {
// If pixel on this face is not transparent, do not add one there
if (!FaceUtil.isVertical(bface)) {
int x2 = x + bface.getModX();
int y2 = y + bface.getModZ();
if (result.readPixel(x2, y2) != MapColorPalette.COLOR_TRANSPARENT) {
continue;
}
}
Face face = new Face();
face.texture = SinglePixelTexture.get(color);
element.faces.put(bface, face);
}
this.elements.add(element);
}
}
}
}
// Apply all textures to the model faces
for (Element element : this.elements) {
element.build(resourcePack, this.textures);
}
}
use of org.bukkit.block.BlockFace in project BKCommonLib by bergerhealer.
the class OrientedBoundingBox method hitTest.
/**
* Performs a hit test to see whether this collision box is hit when
* looked at from a known eye location
*
* @param eyeLocation
* @return distance to the box, Double.MAX_VALUE when not touching.
*/
public double hitTest(Location eyeLocation) {
// Compute start point
Vector p = eyeLocation.toVector().subtract(this.position);
this.orientation_inv.transformPoint(p);
// Check start point already inside box
if (Math.abs(p.getX()) <= this.radius.getX() && Math.abs(p.getY()) <= this.radius.getY() && Math.abs(p.getZ()) <= this.radius.getZ()) {
return 0.0;
}
// Compute direction after rotation
Vector d = eyeLocation.getDirection();
this.orientation_inv.transformPoint(d);
// Check all 6 faces and find the intersection point with this axis
// Then check whether these points are within the range of the box
// If true, compute the distance from the start point and track the smallest value
final double ERR = 1e-6;
double min_distance = Double.MAX_VALUE;
for (BlockFace dir : FaceUtil.BLOCK_SIDES) {
double a, b, c;
if (dir.getModX() != 0) {
// x
a = this.radius.getX() * dir.getModX();
b = p.getX();
c = d.getX();
} else if (dir.getModY() != 0) {
// y
a = this.radius.getY() * dir.getModY();
b = p.getY();
c = d.getY();
} else {
// z
a = this.radius.getZ() * dir.getModZ();
b = p.getZ();
c = d.getZ();
}
if (c == 0.0) {
continue;
}
// Find how many steps of d (c) it takes to reach the box border (a) from p (b)
double f = ((a - b) / c);
if (f < 0.0) {
continue;
}
// Check is potential minimum distance first
if (f > min_distance) {
continue;
}
// Check hit point within bounds of box
if ((Math.abs(p.getX() + f * d.getX()) - this.radius.getX()) > ERR) {
continue;
}
if ((Math.abs(p.getY() + f * d.getY()) - this.radius.getY()) > ERR) {
continue;
}
if ((Math.abs(p.getZ() + f * d.getZ()) - this.radius.getZ()) > ERR) {
continue;
}
// Since d is a unit vector, f is now the distance we need
min_distance = f;
}
return min_distance;
}
Aggregations