public void setAllColorSources(DefaultColorSource source) { for (BlockPart part : BlockPart.values()) { colorSources.put(part, source); } }
@Override public BlockShapeData deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { BlockShapeData shape = new BlockShapeData(); JsonObject shapeObj = json.getAsJsonObject(); if (shapeObj.has(DISPLAY_NAME)) { shape.setDisplayName(shapeObj.getAsJsonPrimitive(DISPLAY_NAME).getAsString()); } for (BlockPart part : BlockPart.values()) { if (shapeObj.has(part.toString().toLowerCase(Locale.ENGLISH))) { JsonObject meshObj = shapeObj.getAsJsonObject(part.toString().toLowerCase(Locale.ENGLISH)); shape.setMeshPart(part, (BlockMeshPart) context.deserialize(meshObj, BlockMeshPart.class)); if (part.isSide() && meshObj.has(FULL_SIDE)) { shape.setBlockingSide(part.getSide(), meshObj.get(FULL_SIDE).getAsBoolean()); } } } if (shapeObj.has(COLLISION) && shapeObj.get(COLLISION).isJsonObject()) { JsonObject collisionInfo = shapeObj.get(COLLISION).getAsJsonObject(); processCollision(context, shape, collisionInfo); } else { shape.setCollisionShape(COLLISION_SHAPE_FACTORY.getNewUnitCube()); shape.setCollisionSymmetric(true); } return shape; }
if (jsonObject.has(singleName)) { T value = context.deserialize(jsonObject.get(singleName), type); for (BlockPart blockPart : BlockPart.values()) { supplier.get().put(blockPart, value); if (partsObject.has("all")) { T value = context.deserialize(partsObject.get("all"), type); for (BlockPart blockPart : BlockPart.values()) { supplier.get().put(blockPart, value); for (BlockPart blockPart : BlockPart.horizontalSides()) { supplier.get().put(blockPart, value); supplier.get().put(BlockPart.BOTTOM, value); for (BlockPart part : BlockPart.values()) { String partName = part.toString().toLowerCase(Locale.ENGLISH); if (partsObject.has(partName)) { T value = context.deserialize(partsObject.get(partName), type);
private BlockAppearance createAppearance(BlockShape shape, Map<BlockPart, BlockTile> tiles, Rotation rot) { Map<BlockPart, BlockMeshPart> meshParts = Maps.newEnumMap(BlockPart.class); Map<BlockPart, Vector2f> textureAtlasPositions = Maps.newEnumMap(BlockPart.class); for (BlockPart part : BlockPart.values()) { // TODO: Need to be more sensible with the texture atlas. Because things like block particles read from a part that may not exist, we're being fairly lenient Vector2f atlasPos; if (tiles.get(part) == null) { atlasPos = new Vector2f(); } else { atlasPos = worldAtlas.getTexCoords(tiles.get(part), shape.getMeshPart(part) != null); } BlockPart targetPart = part.rotate(rot); textureAtlasPositions.put(targetPart, atlasPos); if (shape.getMeshPart(part) != null) { meshParts.put(targetPart, shape.getMeshPart(part).rotate(rot.getQuat4f()).mapTexCoords(atlasPos, worldAtlas.getRelativeTileSize())); } } return new BlockAppearance(meshParts, textureAtlasPositions); }
private boolean hasRequiredSupportOnSideForBlock(Vector3i location, Side sideChanged, Block block) { final BlockMeshPart part = block.getPrimaryAppearance().getPart(BlockPart.fromSide(sideChanged)); if (part != null) { // This block has mesh on this side, therefore it requires a support on that side if (!hasSupportFromBlockOnSide(location, sideChanged, Collections.<Vector3i, Block>emptyMap())) { return false; } } return true; }
/** * Computes n random offset values for each block part texture. * * @param blockAppearance the block appearance information to generate offsets from * @param scale the scale of the texture area (should be in 0 < scale <= 1.0) * * @return a list of random offsets sampled from all block parts */ private List<Vector2f> computeOffsets(BlockAppearance blockAppearance, float scale) { final float relativeTileSize = worldAtlas.getRelativeTileSize(); final int absoluteTileSize = worldAtlas.getTileSize(); final float pixelSize = relativeTileSize / absoluteTileSize; final int spriteWidth = TeraMath.ceilToInt(scale * absoluteTileSize); final Stream<Vector2f> baseOffsets = Arrays.stream(BlockPart.sideValues()).map(blockAppearance::getTextureAtlasPos); return baseOffsets.flatMap(baseOffset -> IntStream.range(0, 8).boxed().map(i -> new Vector2f(baseOffset).add(random.nextInt(absoluteTileSize - spriteWidth) * pixelSize, random.nextInt(absoluteTileSize - spriteWidth) * pixelSize) ) ).collect(Collectors.toList()); }
private void applyLiquidShapes(Block block, Map<BlockPart, BlockTile> tiles) { for (Side side : Side.getAllSides()) { BlockPart part = BlockPart.fromSide(side); BlockTile blockTile = tiles.get(part); if (blockTile != null) { BlockMeshPart lowMeshPart = lowShape .getMeshPart(part) .mapTexCoords(worldAtlas.getTexCoords(blockTile, true), worldAtlas.getRelativeTileSize()); block.setLowLiquidMesh(part.getSide(), lowMeshPart); BlockMeshPart topMeshPart = topShape .getMeshPart(part) .mapTexCoords(worldAtlas.getTexCoords(blockTile, true), worldAtlas.getRelativeTileSize()); block.setTopLiquidMesh(part.getSide(), topMeshPart); } } }
public void setColorSource(BlockColorSource colorSource) { for (BlockPart part : BlockPart.values()) { this.colorSource.put(part, colorSource); } }
public void setColorOffsets(Vector4f color) { for (BlockPart part : BlockPart.values()) { colorOffsets.put(part, color); } }
public void setAllTiles(BlockTile tile) { for (BlockPart part : BlockPart.values()) { blockTiles.put(part, tile); } }
public BlockAppearance(Map<BlockPart, BlockMeshPart> blockParts, Map<BlockPart, Vector2f> textureAtlasPos) { Preconditions.checkNotNull(blockParts); Preconditions.checkNotNull(textureAtlasPos); this.blockParts = blockParts; this.textureAtlasPos.putAll(textureAtlasPos); for (BlockPart part : BlockPart.values()) { Preconditions.checkNotNull("Missing texture atlas position for part " + part, textureAtlasPos.get(part)); } }
/** * Init. a new block with default properties in place. */ public Block() { for (BlockPart part : BlockPart.values()) { colorSource.put(part, DefaultColorSource.DEFAULT); colorOffsets.put(part, new Vector4f(1.0f, 1.0f, 1.0f, 1.0f)); } }
public void setAllColorOffsets(BaseVector4f offset) { for (BlockPart part : BlockPart.values()) { colorOffsets.put(part, new Vector4f(offset)); } }
private List<Vector3f> buildVertList(BlockShapeData shape) { List<Vector3f> result = new ArrayList<>(); for (BlockPart part : BlockPart.values()) { BlockMeshPart meshPart = shape.getMeshPart(part); if (meshPart != null) { for (int i = 0; i < meshPart.size(); ++i) { result.add(meshPart.getVertex(i)); } } } return result; }
public SectionDefinitionData() { colorSources = Maps.newEnumMap(BlockPart.class); colorOffsets = Maps.newEnumMap(BlockPart.class); for (BlockPart part : BlockPart.values()) { colorSources.put(part, DefaultColorSource.DEFAULT); colorOffsets.put(part, new Vector4f(1, 1, 1, 1)); } }
public BlockAppearance() { blockParts = Maps.newEnumMap(BlockPart.class); textureAtlasPos = Maps.newEnumMap(BlockPart.class); for (BlockPart part : BlockPart.values()) { textureAtlasPos.put(part, new Vector2f()); } }
private void applyDefaults(ResourceUrn resourceUrn, SectionDefinitionData section) { Optional<BlockTile> defaultTile = assetManager.getAsset(resourceUrn, BlockTile.class); if (defaultTile.isPresent()) { for (BlockPart part : BlockPart.values()) { if (section.getBlockTiles().get(part) == null) { section.getBlockTiles().put(part, defaultTile.get()); } } } if (section.getSounds() == null) { section.setSounds(assetManager.getAsset(DEFAULT_SOUNDS, BlockSounds.class).get()); } }