use of me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker in project MissileWarfare by koiboi-dev.
the class AntiMissileLauncher method preRegister.
@Override
public void preRegister() {
// cancel thing on place
BlockPlaceHandler blockPlaceHandler = new BlockPlaceHandler(false) {
@Override
public void onPlayerPlace(BlockPlaceEvent event) {
BlockData data = event.getBlockPlaced().getBlockData();
((Directional) data).setFacing(BlockFace.UP);
event.getBlockPlaced().setBlockData(data);
Block block = event.getBlockPlaced();
// Block bottom = world.getBlockAt(event.getBlock().getLocation().subtract(new Vector(0, 2, 0)));
if (correctlyBuilt(block)) {
event.getPlayer().sendMessage(Translations.get("messages.launchers.createantiair.success"));
} else {
event.getPlayer().sendMessage(Translations.get("messages.launchers.createantiair.failure"));
}
}
};
addItemHandler(blockPlaceHandler);
BlockDispenseHandler blockDispenseHandler = this::blockDispense;
addItemHandler(blockDispenseHandler);
addItemHandler(new BlockTicker() {
@Override
public boolean isSynchronized() {
return true;
}
@Override
public void tick(Block block, SlimefunItem slimefunItem, Config config) {
TileState state = (TileState) block.getState();
PersistentDataContainer cont = state.getPersistentDataContainer();
if (!block.isBlockPowered()) {
List<MissileController> missiles = MissileWarfare.activemissiles;
MissileController locked = null;
if (!missiles.isEmpty()) {
for (MissileController missile : missiles) {
if (block.getLocation().distanceSquared(missile.pos.toLocation(missile.world)) < range && missile.isgroundmissile) {
locked = missile;
break;
}
}
}
state.update();
try {
if (locked != null && cont.get(new NamespacedKey(MissileWarfare.getInstance(), "timesincelastshot"), PersistentDataType.INTEGER) <= System.currentTimeMillis()) {
cont.set(new NamespacedKey(MissileWarfare.getInstance(), "timesincelastshot"), PersistentDataType.INTEGER, (int) System.currentTimeMillis() + 1000);
fireMissile((Dispenser) block.getState(), locked);
}
} catch (NullPointerException e) {
cont.set(new NamespacedKey(MissileWarfare.getInstance(), "timesincelastshot"), PersistentDataType.INTEGER, Integer.MIN_VALUE);
state.update();
}
}
}
});
}
use of me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker in project Slimefun4 by Slimefun.
the class GPSTransmitter method getItemHandler.
@Override
public BlockTicker getItemHandler() {
return new BlockTicker() {
@Override
public void tick(Block b, SlimefunItem item, Config data) {
int charge = getCharge(b.getLocation(), data);
UUID owner = UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner"));
if (charge >= getEnergyConsumption()) {
Slimefun.getGPSNetwork().updateTransmitter(b.getLocation(), owner, true);
removeCharge(b.getLocation(), getEnergyConsumption());
} else {
Slimefun.getGPSNetwork().updateTransmitter(b.getLocation(), owner, false);
}
}
@Override
public boolean isSynchronized() {
return false;
}
};
}
use of me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker in project Slimefun4 by Slimefun.
the class EnhancedFurnace method getItemHandler.
@Override
public BlockTicker getItemHandler() {
return new BlockTicker() {
@Override
public void tick(Block b, SlimefunItem item, Config data) {
if (b.getType() != Material.FURNACE) {
// The Furnace has been destroyed, we can clear the block data
BlockStorage.clearBlockInfo(b);
} else {
BlockStateSnapshotResult result = PaperLib.getBlockState(b, false);
BlockState state = result.getState();
// Check if the BlockState is a Furnace and cooking something
if (state instanceof Furnace && ((Furnace) state).getCookTime() > 0) {
setProgress((Furnace) state);
// Only update if necessary
if (result.isSnapshot()) {
state.update(true, false);
}
}
}
}
@Override
public boolean isSynchronized() {
// This messes with BlockStates, so it needs to be synchronized
return true;
}
};
}
use of me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker in project Slimefun4 by Slimefun.
the class AbstractEntityAssembler method getItemHandler.
@Override
public BlockTicker getItemHandler() {
return new BlockTicker() {
@Override
public void tick(Block b, SlimefunItem sf, Config data) {
if ("false".equals(BlockStorage.getLocationInfo(b.getLocation(), KEY_ENABLED))) {
return;
}
if (lifetime % 60 == 0 && getCharge(b.getLocation(), data) >= getEnergyConsumption()) {
BlockMenu menu = BlockStorage.getInventory(b);
boolean hasBody = findResource(menu, getBody(), bodySlots);
boolean hasHead = findResource(menu, getHead(), headSlots);
if (hasBody && hasHead) {
consumeResources(menu);
removeCharge(b.getLocation(), getEnergyConsumption());
double offset = Double.parseDouble(BlockStorage.getLocationInfo(b.getLocation(), KEY_OFFSET));
Slimefun.runSync(() -> {
Location loc = new Location(b.getWorld(), b.getX() + 0.5D, b.getY() + offset, b.getZ() + 0.5D);
spawnEntity(loc);
b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, getHead().getType());
});
}
}
}
@Override
public void uniqueTick() {
lifetime++;
}
@Override
public boolean isSynchronized() {
return false;
}
};
}
use of me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker in project Slimefun4 by Slimefun.
the class AbstractGrowthAccelerator method preRegister.
@Override
public void preRegister() {
super.preRegister();
addItemHandler(new BlockTicker() {
@Override
public void tick(Block b, SlimefunItem sf, Config data) {
AbstractGrowthAccelerator.this.tick(b);
}
@Override
public boolean isSynchronized() {
return true;
}
});
}
Aggregations