mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Sync grow event, patch set fnction, path blockstateslist
This commit is contained in:
parent
696cf61fe9
commit
68e6bd668c
@ -12,6 +12,7 @@ import com.volmit.iris.util.data.Cuboid;
|
|||||||
import com.volmit.iris.util.math.BlockPosition;
|
import com.volmit.iris.util.math.BlockPosition;
|
||||||
import com.volmit.iris.util.math.RNG;
|
import com.volmit.iris.util.math.RNG;
|
||||||
import com.volmit.iris.util.math.Vector2d;
|
import com.volmit.iris.util.math.Vector2d;
|
||||||
|
import com.volmit.iris.util.scheduling.J;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
@ -86,6 +87,10 @@ public class TreeManager implements Listener {
|
|||||||
// Get object from placer
|
// Get object from placer
|
||||||
IrisObject object = worldAccess.getData().getObjectLoader().load(placement.getPlace().getRandom(RNG.r));
|
IrisObject object = worldAccess.getData().getObjectLoader().load(placement.getPlace().getRandom(RNG.r));
|
||||||
|
|
||||||
|
// List of new blocks
|
||||||
|
List<BlockState> blockStateList = new KList<>();
|
||||||
|
saplingPlane.forEach(b -> blockStateList.add(b.getState()));
|
||||||
|
|
||||||
// Create object placer
|
// Create object placer
|
||||||
IObjectPlacer placer = new IObjectPlacer() {
|
IObjectPlacer placer = new IObjectPlacer() {
|
||||||
|
|
||||||
@ -102,12 +107,9 @@ public class TreeManager implements Listener {
|
|||||||
@Override
|
@Override
|
||||||
public void set(int x, int y, int z, BlockData d) {
|
public void set(int x, int y, int z, BlockData d) {
|
||||||
Block b = event.getWorld().getBlockAt(x, y, z);
|
Block b = event.getWorld().getBlockAt(x, y, z);
|
||||||
|
BlockState state = b.getState();
|
||||||
// Set the block
|
state.setBlockData(d);
|
||||||
b.setBlockData(d, false);
|
blockStateList.add(b.getState());
|
||||||
|
|
||||||
// Tell bukkit what you're doing here
|
|
||||||
event.getBlocks().add(b.getState());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -156,15 +158,6 @@ public class TreeManager implements Listener {
|
|||||||
|
|
||||||
// TODO: Prevent placing object when overriding blocks
|
// TODO: Prevent placing object when overriding blocks
|
||||||
|
|
||||||
// Cancel the vanilla placement
|
|
||||||
event.setCancelled(true);
|
|
||||||
|
|
||||||
// Send out a new event
|
|
||||||
List<BlockState> blockStateList = new KList<>();
|
|
||||||
saplingPlane.forEach(b -> blockStateList.add(b.getState()));
|
|
||||||
StructureGrowEvent iGrow = new StructureGrowEvent(event.getLocation(), event.getSpecies(), event.isFromBonemeal(), event.getPlayer(), blockStateList);
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(iGrow);
|
|
||||||
|
|
||||||
// Place the object with the placer
|
// Place the object with the placer
|
||||||
object.place(
|
object.place(
|
||||||
saplingPlane.getCenter(),
|
saplingPlane.getCenter(),
|
||||||
@ -173,6 +166,24 @@ public class TreeManager implements Listener {
|
|||||||
RNG.r,
|
RNG.r,
|
||||||
Objects.requireNonNull(worldAccess).getData()
|
Objects.requireNonNull(worldAccess).getData()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Cancel the vanilla placement
|
||||||
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
// Queue sync task
|
||||||
|
J.s(() -> {
|
||||||
|
|
||||||
|
// Send out a new event
|
||||||
|
StructureGrowEvent iGrow = new StructureGrowEvent(event.getLocation(), event.getSpecies(), event.isFromBonemeal(), event.getPlayer(), blockStateList);
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(iGrow);
|
||||||
|
|
||||||
|
// Check if blocks need to be updated
|
||||||
|
if(!iGrow.isCancelled()){
|
||||||
|
for (BlockState block : iGrow.getBlocks()) {
|
||||||
|
block.update(true, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user