use of org.spongepowered.api.block.BlockSnapshot in project SpongeCommon by SpongePowered.
the class SpongeBlockSnapshot method merge.
@Override
public BlockSnapshot merge(BlockSnapshot that, MergeFunction function) {
BlockSnapshot merged = this;
merged = merged.withState(function.merge(this.blockState, that.getState()));
for (ImmutableDataManipulator<?, ?> manipulator : that.getContainers()) {
Optional<BlockSnapshot> optional = merged.with(function.merge(this.get(manipulator.getClass()).orElse(null), manipulator));
if (optional.isPresent()) {
merged = optional.get();
}
}
return merged;
}
use of org.spongepowered.api.block.BlockSnapshot in project SpongeCommon by SpongePowered.
the class SpongeBlockSnapshot method with.
@Override
public Optional<BlockSnapshot> with(Iterable<ImmutableDataManipulator<?, ?>> valueContainers) {
BlockSnapshot snapshot = this;
for (ImmutableDataManipulator<?, ?> manipulator : valueContainers) {
final Optional<BlockSnapshot> optional = snapshot.with(manipulator);
if (!optional.isPresent()) {
return Optional.empty();
}
snapshot = optional.get();
}
return Optional.of(snapshot);
}
use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.
the class AntiCactusFarmListener method onItemDrop.
@Listener
public void onItemDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) BlockSpawnCause spawnCause) {
if (event.getCause().containsType(Player.class)) {
return;
}
BlockSnapshot blockSnapshot = spawnCause.getBlockSnapshot();
Optional<Location<World>> optLocation = blockSnapshot.getLocation();
if (!optLocation.isPresent()) {
return;
}
Location<World> location = optLocation.get();
while (true) {
location = location.add(0, -1, 0);
if (location.getBlockType() != BlockTypes.CACTUS) {
break;
}
location.setBlockType(BlockTypes.AIR, Cause.source(SkreePlugin.container()).build());
}
}
use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.
the class GoldRushListener method onPlayerInteractEvent.
@Listener(order = Order.FIRST)
public void onPlayerInteractEvent(InteractBlockEvent.Secondary.MainHand event, @Root Player player) {
Optional<GoldRushInstance> optInst = manager.getApplicableZone(player);
if (!optInst.isPresent()) {
return;
}
GoldRushInstance inst = optInst.get();
BlockSnapshot snapshot = event.getTargetBlock();
BlockState state = snapshot.getState();
if (!snapshot.getLocation().isPresent()) {
return;
}
Location<World> targetBlock = snapshot.getLocation().get();
if (state.getType() == BlockTypes.WALL_SIGN && inst.getLockLocations().contains(targetBlock)) {
Optional<TileEntity> optTileEnt = snapshot.getLocation().get().getTileEntity();
if (!optTileEnt.isPresent()) {
return;
}
TileEntity tileEntity = optTileEnt.get();
Optional<List<Text>> optTexts = tileEntity.get(Keys.SIGN_LINES);
if (!optTexts.isPresent()) {
return;
}
List<Text> texts = optTexts.get();
boolean unlocked = false;
String text = texts.get(1).toPlain().toLowerCase();
NonNullList<ItemStack> itemStacks = tf(player).inventory.mainInventory;
for (int i = 0; i < itemStacks.size(); ++i) {
ItemStack is = itemStacks.get(i);
if (is == ItemStack.EMPTY || is.getItem() != CustomItemTypes.GOLD_RUSH_KEY) {
continue;
}
if (text.contains("blue")) {
if (is.getItemDamage() != 1) {
continue;
}
} else if (text.contains("red")) {
if (is.getItemDamage() != 0) {
continue;
}
} else {
continue;
}
unlocked = true;
itemStacks.set(i, ItemStack.EMPTY);
break;
}
if (unlocked) {
tf(player).inventoryContainer.detectAndSendChanges();
texts.set(2, Text.of("Locked"));
texts.set(3, Text.of("- Unlocked -"));
tileEntity.offer(Keys.SIGN_LINES, texts);
}
} else if (state.getType() == BlockTypes.LEVER) {
Task.builder().execute(() -> {
if (inst.checkLevers()) {
inst.completeGame();
}
}).delayTicks(1).submit(SkreePlugin.inst());
} else if (targetBlock.equals(inst.getRewardChestLoc()) && inst.isComplete()) {
event.setUseItemResult(Tristate.FALSE);
event.setUseBlockResult(Tristate.FALSE);
player.sendMessage(Text.of(TextColors.YELLOW, "You have successfully robbed the bank!"));
inst.payPlayer(player);
} else if (!inst.isLocked()) {
if (state.getType() == BlockTypes.STONE_BUTTON) {
inst.tryToStart();
}
}
}
use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.
the class CursedMineListener method onBlockBreak.
@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @Named(NamedCause.SOURCE) Player player) {
Optional<CursedMineInstance> optInst = manager.getApplicableZone(player);
if (!optInst.isPresent()) {
return;
}
CursedMineInstance inst = optInst.get();
Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optHeldItem.isPresent()) {
event.setCancelled(true);
return;
}
for (Transaction<BlockSnapshot> block : event.getTransactions()) {
BlockType originalType = block.getOriginal().getState().getType();
if (cursedOres.contains(originalType)) {
// we were having some multi-firing problems
if (inst.recordBlockBreak(player, new BlockRecord(block.getOriginal()))) {
/*if (Probability.getChance(3000)) {
ChatUtil.send(player, "You feel as though a spirit is trying to tell you something...");
player.getInventory().addItem(BookUtil.Lore.Areas.theGreatMine());
}*/
ExperienceOrb xpOrb = (ExperienceOrb) player.getWorld().createEntity(EntityTypes.EXPERIENCE_ORB, block.getOriginal().getLocation().get().getPosition());
xpOrb.offer(Keys.CONTAINED_EXPERIENCE, (70 - player.getLocation().getBlockY()) / 2);
inst.eatFood(player);
inst.poison(player, 6);
inst.ghost(player, originalType);
}
} else if (stealableFluids.contains(originalType)) {
inst.recordBlockBreak(player, new BlockRecord(block.getOriginal()));
} else {
block.setCustom(block.getOriginal());
}
}
}
Aggregations