mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
remove buffer items
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.buffer;
|
||||
|
||||
import com.dfsek.terra.api.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structure.buffer.BufferedItem;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.chunk.Chunk;
|
||||
|
||||
|
||||
public class IntermediateBuffer implements Buffer {
|
||||
private final Buffer original;
|
||||
private final Vector3 offset;
|
||||
|
||||
public IntermediateBuffer(Buffer original, Vector3 offset) {
|
||||
this.original = original;
|
||||
this.offset = offset.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paste(Vector3 origin, Chunk chunk) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paste(Vector3 origin, ServerWorld world) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public Buffer addItem(BufferedItem item, Vector3 location) {
|
||||
return original.addItem(item, location.clone().add(offset));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Buffer setMark(String mark, Vector3 location) {
|
||||
original.setMark(mark, location.clone().add(offset));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3 getOrigin() {
|
||||
return original.getOrigin().clone().add(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMark(Vector3 location) {
|
||||
return original.getMark(location.clone().add(offset));
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.buffer.items;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.api.event.events.world.generation.EntitySpawnEvent;
|
||||
import com.dfsek.terra.api.structure.buffer.BufferedItem;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.WritableWorld;
|
||||
|
||||
|
||||
public class BufferedEntity implements BufferedItem {
|
||||
|
||||
private final EntityType type;
|
||||
private final Platform platform;
|
||||
|
||||
public BufferedEntity(EntityType type, Platform platform) {
|
||||
this.type = type;
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paste(Vector3 origin, WritableWorld world) {
|
||||
Entity entity = world.spawnEntity(origin.clone().add(0.5, 0, 0.5), type);
|
||||
platform.getEventManager().callEvent(new EntitySpawnEvent(entity.world().getPack(), entity));
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.buffer.items;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.structure.buffer.BufferedItem;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.WritableWorld;
|
||||
|
||||
|
||||
public class BufferedPulledBlock implements BufferedItem {
|
||||
private final BlockState data;
|
||||
|
||||
public BufferedPulledBlock(BlockState data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paste(Vector3 origin, WritableWorld world) {
|
||||
Vector3 mutable = origin.clone();
|
||||
while(mutable.getY() > world.getMinHeight()) {
|
||||
if(!world.getBlockState(mutable).isAir()) {
|
||||
world.setBlockState(mutable, data);
|
||||
break;
|
||||
}
|
||||
mutable.subtract(0, 1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.buffer.items;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.api.block.entity.BlockEntity;
|
||||
import com.dfsek.terra.api.structure.buffer.BufferedItem;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.WritableWorld;
|
||||
|
||||
|
||||
public class BufferedStateManipulator implements BufferedItem {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(BufferedStateManipulator.class);
|
||||
private final String data;
|
||||
|
||||
public BufferedStateManipulator(String state) {
|
||||
this.data = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paste(Vector3 origin, WritableWorld world) {
|
||||
try {
|
||||
BlockEntity state = world.getBlockEntity(origin);
|
||||
state.applyState(data);
|
||||
state.update(false);
|
||||
} catch(Exception e) {
|
||||
LOGGER.warn("Could not apply BlockState at {}", origin, e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,6 @@ import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.structure.buffer.items.BufferedBlock;
|
||||
import com.dfsek.terra.api.util.RotationUtil;
|
||||
import com.dfsek.terra.api.util.vector.Vector2;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
|
||||
@@ -9,7 +9,6 @@ package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.buffer.items.BufferedEntity;
|
||||
import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
|
||||
@@ -11,7 +11,6 @@ import net.jafama.FastMath;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.buffer.items.BufferedPulledBlock;
|
||||
import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
|
||||
@@ -13,14 +13,12 @@ import net.jafama.FastMath;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.buffer.items.BufferedStateManipulator;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.variables.Variable;
|
||||
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.util.RotationUtil;
|
||||
import com.dfsek.terra.api.util.vector.Vector2;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
|
||||
@@ -16,7 +16,6 @@ import org.slf4j.LoggerFactory;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.buffer.IntermediateBuffer;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
@@ -29,7 +28,6 @@ import com.dfsek.terra.api.structure.Structure;
|
||||
import com.dfsek.terra.api.util.Rotation;
|
||||
import com.dfsek.terra.api.util.RotationUtil;
|
||||
import com.dfsek.terra.api.util.vector.Vector2;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
|
||||
|
||||
public class StructureFunction implements Function<Boolean> {
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra API is licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in the common/api directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.api.structure.buffer;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus.Experimental;
|
||||
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.chunk.Chunk;
|
||||
|
||||
|
||||
@Experimental
|
||||
public interface Buffer {
|
||||
void paste(Vector3 origin, Chunk chunk);
|
||||
|
||||
void paste(Vector3 origin, ServerWorld world);
|
||||
|
||||
Buffer addItem(BufferedItem item, Vector3 location);
|
||||
|
||||
Buffer setMark(String mark, Vector3 location);
|
||||
|
||||
Vector3 getOrigin();
|
||||
|
||||
String getMark(Vector3 location);
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra API is licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in the common/api directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.api.structure.buffer;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus.Experimental;
|
||||
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.WritableWorld;
|
||||
|
||||
|
||||
@Experimental
|
||||
public interface BufferedItem {
|
||||
void paste(Vector3 origin, WritableWorld world);
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra API is licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in the common/api directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.api.structure.buffer.items;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus.Experimental;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.properties.base.Properties;
|
||||
import com.dfsek.terra.api.structure.buffer.BufferedItem;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.WritableWorld;
|
||||
|
||||
|
||||
@Experimental
|
||||
public class BufferedBlock implements BufferedItem {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BufferedBlock.class);
|
||||
|
||||
private final BlockState data;
|
||||
private final boolean overwrite;
|
||||
private final Platform platform;
|
||||
private final boolean waterlog;
|
||||
|
||||
public BufferedBlock(BlockState data, boolean overwrite, Platform platform, boolean waterlog) {
|
||||
this.data = data;
|
||||
this.overwrite = overwrite;
|
||||
this.platform = platform;
|
||||
this.waterlog = waterlog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paste(Vector3 origin, WritableWorld world) {
|
||||
try {
|
||||
BlockState current = world.getBlockState(origin);
|
||||
if(overwrite || current.isAir()) {
|
||||
if(waterlog && current.has(Properties.WATERLOGGED) && current.getBlockType().isWater()) {
|
||||
current.set(Properties.WATERLOGGED, true);
|
||||
}
|
||||
world.setBlockState(origin, data);
|
||||
}
|
||||
} catch(RuntimeException e) {
|
||||
logger.error("Failed to place block at location {}", origin, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra API is licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in the common/api directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.api.structure.buffer.items;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus.Experimental;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.api.structure.buffer.BufferedItem;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.WritableWorld;
|
||||
|
||||
|
||||
@Experimental
|
||||
public class Cell implements BufferedItem {
|
||||
private final List<BufferedItem> items = new ArrayList<>();
|
||||
private String mark;
|
||||
|
||||
@Override
|
||||
public void paste(Vector3 origin, WritableWorld world) {
|
||||
items.forEach(item -> item.paste(origin.clone(), world));
|
||||
}
|
||||
|
||||
public void add(BufferedItem item) {
|
||||
items.add(item);
|
||||
}
|
||||
|
||||
public String getMark() {
|
||||
return mark;
|
||||
}
|
||||
|
||||
public void setMark(String mark) {
|
||||
this.mark = mark;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user