use of javax.vecmath.Point3i in project WorldPainter by Captain-Chaos.
the class Schematic method readObject.
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
// Legacy
if (origin != null) {
if (attributes == null) {
attributes = new HashMap<>();
}
attributes.put(ATTRIBUTE_OFFSET.key, new Point3i(-origin.x, -origin.y, -origin.z));
origin = null;
}
if (version == 0) {
if (!attributes.containsKey(ATTRIBUTE_LEAF_DECAY_MODE.key)) {
attributes.put(ATTRIBUTE_LEAF_DECAY_MODE.key, LEAF_DECAY_ON);
}
version = 1;
}
}
use of javax.vecmath.Point3i in project WorldPainter by Captain-Chaos.
the class LayerPreviewCreator method renderPreview.
public MinecraftWorldObject renderPreview() {
// Phase one: setup
long timestamp = System.currentTimeMillis();
long seed = 0L;
TileFactory tileFactory = subterranean ? TileFactoryFactory.createNoiseTileFactory(seed, Terrain.BARE_GRASS, previewHeight, 56, 62, false, true, 20f, 0.5) : TileFactoryFactory.createNoiseTileFactory(seed, Terrain.BARE_GRASS, previewHeight, 8, 14, false, true, 20f, 0.5);
Dimension dimension = new Dimension(seed, tileFactory, DIM_NORMAL, previewHeight);
dimension.setSubsurfaceMaterial(Terrain.STONE);
MinecraftWorldObject minecraftWorldObject = new MinecraftWorldObject(layer.getName() + " Preview", new Box(-8, 136, -8, 136, 0, previewHeight), previewHeight, null, new Point3i(-64, -64, 0));
long now = System.currentTimeMillis();
if (logger.isDebugEnabled()) {
logger.debug("Creating data structures took " + (now - timestamp) + " ms");
}
// Phase two: apply layer to dimension
timestamp = now;
Tile tile = tileFactory.createTile(0, 0);
switch(layer.getDataSize()) {
case BIT:
Random random = new Random(seed);
for (int x = 0; x < 128; x++) {
for (int y = 0; y < 128; y++) {
if (random.nextFloat() < pattern.getStrength(x, y)) {
tile.setBitLayerValue(layer, x, y, true);
}
}
}
break;
case BIT_PER_CHUNK:
random = new Random(seed);
for (int x = 0; x < 128; x += 16) {
for (int y = 0; y < 128; y += 16) {
if (random.nextFloat() < pattern.getStrength(x, y)) {
tile.setBitLayerValue(layer, x, y, true);
}
}
}
break;
case BYTE:
for (int x = 0; x < 128; x++) {
for (int y = 0; y < 128; y++) {
tile.setLayerValue(layer, x, y, Math.min((int) (pattern.getStrength(x, y) * 256), 255));
}
}
break;
case NIBBLE:
// any
if (layer instanceof CombinedLayer) {
final Terrain terrain = ((CombinedLayer) layer).getTerrain();
final int biome = ((CombinedLayer) layer).getBiome();
final boolean terrainConfigured = terrain != null;
final boolean biomeConfigured = biome != -1;
for (int x = 0; x < 128; x++) {
for (int y = 0; y < 128; y++) {
float strength = pattern.getStrength(x, y);
tile.setLayerValue(layer, x, y, Math.min((int) (strength * 16), 15));
// Double the strength so that 50% intensity results
// in full coverage for terrain and biome, which is
// inaccurate but probably more closely resembles
// practical usage
strength = Math.min(strength * 2, 1.0f);
if (terrainConfigured && ((strength > 0.95f) || (Math.random() < strength))) {
tile.setTerrain(x, y, terrain);
}
if (biomeConfigured && ((strength > 0.95f) || (Math.random() < strength))) {
tile.setLayerValue(Biome.INSTANCE, x, y, biome);
}
}
}
} else {
for (int x = 0; x < 128; x++) {
for (int y = 0; y < 128; y++) {
tile.setLayerValue(layer, x, y, Math.min((int) (pattern.getStrength(x, y) * 16), 15));
}
}
}
break;
default:
throw new IllegalArgumentException("Unsupported data size " + layer.getDataSize() + " encountered");
}
// If the layer is a combined layer, apply it recursively and collect
// the added layers
List<Layer> layers;
if (layer instanceof CombinedLayer) {
layers = new ArrayList<>();
layers.add(layer);
while (true) {
List<Layer> addedLayers = new ArrayList<>();
for (Iterator<Layer> i = layers.iterator(); i.hasNext(); ) {
Layer tmpLayer = i.next();
if (tmpLayer instanceof CombinedLayer) {
i.remove();
addedLayers.addAll(((CombinedLayer) tmpLayer).apply(tile));
}
}
if (!addedLayers.isEmpty()) {
layers.addAll(addedLayers);
} else {
break;
}
}
} else {
layers = Collections.singletonList(layer);
}
dimension.addTile(tile);
now = System.currentTimeMillis();
if (logger.isDebugEnabled()) {
logger.debug("Applying layer(s) took " + (now - timestamp) + " ms");
}
// Collect the exporters (could be multiple if the layer was a combined
// layer)
Map<Layer, LayerExporter> pass1Exporters = new HashMap<>();
Map<Layer, SecondPassLayerExporter> pass2Exporters = new HashMap<>();
for (Layer tmpLayer : layers) {
LayerExporter exporter = tmpLayer.getExporter();
if (tmpLayer.equals(layer)) {
exporter.setSettings(settings);
}
if (exporter instanceof FirstPassLayerExporter) {
pass1Exporters.put(layer, exporter);
}
if (exporter instanceof SecondPassLayerExporter) {
pass2Exporters.put(layer, (SecondPassLayerExporter) exporter);
}
}
// Phase three: generate terrain and render first pass layers, if any
timestamp = now;
WorldPainterChunkFactory chunkFactory = new WorldPainterChunkFactory(dimension, pass1Exporters, DefaultPlugin.JAVA_ANVIL, previewHeight);
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
Chunk chunk = chunkFactory.createChunk(x, y).chunk;
minecraftWorldObject.addChunk(chunk);
}
}
now = System.currentTimeMillis();
if (logger.isDebugEnabled()) {
logger.debug("Generating terrain and rendering first pass layer(s) (if any) took " + (now - timestamp) + " ms");
}
if (!pass2Exporters.isEmpty()) {
// Phase four: render the second pass layers, if any
timestamp = now;
Rectangle area = new Rectangle(128, 128);
for (SecondPassLayerExporter exporter : pass2Exporters.values()) {
exporter.render(dimension, area, area, minecraftWorldObject);
}
now = System.currentTimeMillis();
if (logger.isDebugEnabled()) {
logger.debug("Rendering second pass layer(s) took " + (now - timestamp) + " ms");
}
}
// Final phase: post processing
timestamp = now;
now = System.currentTimeMillis();
try {
new JavaPostProcessor().postProcess(minecraftWorldObject, new Rectangle(-8, -8, 136, 136), null);
} catch (ProgressReceiver.OperationCancelled e) {
// Can't happen since we didn't pass in a progress receiver
throw new InternalError();
}
if (logger.isDebugEnabled()) {
logger.debug("Post processing took " + (now - timestamp) + " ms");
}
return minecraftWorldObject;
}
use of javax.vecmath.Point3i in project WorldPainter by Captain-Chaos.
the class EditObjectAttributes method ok.
private void ok() {
boolean singleSelection = objects.size() == 1;
for (WPObject object : objects) {
if (singleSelection && (!fieldName.getText().trim().isEmpty())) {
object.setName(fieldName.getText().trim());
}
Map<String, Serializable> attributes = object.getAttributes();
if (attributes == null) {
attributes = new HashMap<>();
}
if (checkBoxFrequencyActive.isSelected()) {
int frequency = (Integer) spinnerFrequency.getValue();
if (frequency != 100) {
attributes.put(ATTRIBUTE_FREQUENCY.key, frequency);
} else {
attributes.remove(ATTRIBUTE_FREQUENCY.key);
}
}
Point3i offset = offsets.get(object);
if ((offset != null) && ((offset.x != 0) || (offset.y != 0) || (offset.z != 0))) {
attributes.put(ATTRIBUTE_OFFSET.key, offset);
} else {
attributes.remove(ATTRIBUTE_OFFSET.key);
}
if (!checkBoxRandomRotation.isMixed()) {
attributes.put(ATTRIBUTE_RANDOM_ROTATION.key, checkBoxRandomRotation.isSelected());
}
if (!checkBoxOnAir.isMixed()) {
attributes.put(ATTRIBUTE_NEEDS_FOUNDATION.key, !checkBoxOnAir.isSelected());
}
if (!checkBoxUnderLava.isMixed()) {
attributes.put(ATTRIBUTE_SPAWN_IN_LAVA.key, checkBoxUnderLava.isSelected());
}
if (!checkBoxUnderWater.isMixed()) {
attributes.put(ATTRIBUTE_SPAWN_IN_WATER.key, checkBoxUnderWater.isSelected());
}
if (!checkBoxOnSolidLand.isMixed()) {
attributes.put(ATTRIBUTE_SPAWN_ON_LAND.key, checkBoxOnSolidLand.isSelected());
}
if (!checkBoxOnWater.isMixed()) {
attributes.put(ATTRIBUTE_SPAWN_ON_WATER.key, checkBoxOnWater.isSelected());
}
if (!checkBoxOnLava.isMixed()) {
attributes.put(ATTRIBUTE_SPAWN_ON_LAVA.key, checkBoxOnLava.isSelected());
}
if (singleSelection || comboBoxCollisionMode.getSelectedIndex() > 0) {
attributes.put(ATTRIBUTE_COLLISION_MODE.key, comboBoxCollisionMode.getSelectedIndex() + (singleSelection ? 1 : 0));
}
if (singleSelection || comboBoxUndergroundMode.getSelectedIndex() > 0) {
attributes.put(ATTRIBUTE_UNDERGROUND_MODE.key, comboBoxUndergroundMode.getSelectedIndex() + (singleSelection ? 1 : 0));
}
if (singleSelection || comboBoxLeafDecayMode.getSelectedIndex() > 0) {
attributes.put(ATTRIBUTE_LEAF_DECAY_MODE.key, comboBoxLeafDecayMode.getSelectedIndex() + (singleSelection ? 1 : 0));
}
if (singleSelection) {
if (checkBoxReplace.isSelected()) {
attributes.put(ATTRIBUTE_REPLACE_WITH_AIR.key, new int[] { comboBoxReplaceBlockId.getSelectedIndex(), (Integer) spinnerReplaceData.getValue() });
} else {
attributes.remove(ATTRIBUTE_REPLACE_WITH_AIR.key);
}
}
if (!checkBoxExtendFoundation.isMixed()) {
attributes.put(ATTRIBUTE_EXTEND_FOUNDATION.key, checkBoxExtendFoundation.isSelected());
}
if (!attributes.isEmpty()) {
object.setAttributes(attributes);
} else {
object.setAttributes(null);
}
}
cancelled = false;
dispose();
}
use of javax.vecmath.Point3i in project WorldPainter by Captain-Chaos.
the class EditObjectAttributes method autoOffset.
private void autoOffset() {
boolean singleSelection = objects.size() == 1;
for (WPObject object : objects) {
Point3i offset = object.guestimateOffset();
if (offset == null) {
// This object has size zero or consists of nothing but air!
offsets.clear();
if (singleSelection) {
labelOffset.setText("<html><u>0, 0, 0</u></html>");
}
} else {
offsets.put(object, offset);
if (singleSelection) {
String offsetStr = "<html><u>" + offset.x + ", " + offset.y + ", " + offset.z + "</u></html>";
labelOffset.setText(offsetStr);
}
}
}
if (!singleSelection) {
JOptionPane.showMessageDialog(this, objects.size() + " offsets autoset");
}
}
use of javax.vecmath.Point3i in project WorldPainter by Captain-Chaos.
the class WorldRegion method save.
public void save(File worldDir, int dimension) throws IOException {
try (ChunkStore chunkStore = platformProvider.getChunkStore(platform, worldDir, dimension)) {
chunkStore.doInTransaction(() -> {
for (int x = 0; x < CHUNKS_PER_SIDE; x++) {
for (int z = 0; z < CHUNKS_PER_SIDE; z++) {
final Chunk chunk = chunks[x + 1][z + 1];
if (chunk != null) {
// Do some sanity checks first
if (chunk.getTileEntities() != null) {
// contains data are actually there
for (Iterator<TileEntity> i = chunk.getTileEntities().iterator(); i.hasNext(); ) {
final TileEntity tileEntity = i.next();
final Set<Integer> blockIds = Constants.TILE_ENTITY_MAP.get(tileEntity.getId());
if (blockIds == null) {
logger.warn("Unknown tile entity ID \"" + tileEntity.getId() + "\" encountered @ " + tileEntity.getX() + "," + tileEntity.getZ() + "," + tileEntity.getY() + "; can't check whether the corresponding block is there!");
} else {
final int existingBlockId = chunk.getBlockType(tileEntity.getX() & 0xf, tileEntity.getY(), tileEntity.getZ() & 0xf);
if (!blockIds.contains(existingBlockId)) {
// The block at the specified location
// is not a tile entity, or a different
// tile entity. Remove the data
i.remove();
if (logger.isDebugEnabled()) {
logger.debug("Removing tile entity " + tileEntity.getId() + " @ " + tileEntity.getX() + "," + tileEntity.getZ() + "," + tileEntity.getY() + " because the block at that location is a " + BLOCK_TYPE_NAMES[existingBlockId]);
}
}
}
}
// Check that there aren't multiple tile entities (of the same type,
// otherwise they would have been removed above) in the same location
Set<Point3i> occupiedCoords = new HashSet<>();
for (Iterator<TileEntity> i = chunk.getTileEntities().iterator(); i.hasNext(); ) {
TileEntity tileEntity = i.next();
Point3i coords = new Point3i(tileEntity.getX(), tileEntity.getZ(), tileEntity.getY());
if (occupiedCoords.contains(coords)) {
// There is already tile data for that location in the chunk;
// remove this copy
i.remove();
logger.warn("Removing tile entity " + tileEntity.getId() + " @ " + tileEntity.getX() + "," + tileEntity.getZ() + "," + tileEntity.getY() + " because there is already a tile entity of the same type at that location");
} else {
occupiedCoords.add(coords);
}
}
}
chunkStore.saveChunk(chunk);
}
}
}
});
}
}
Aggregations