use of org.spongepowered.api.block.BlockType in project Skree by Skelril.
the class WildernessWorldWrapper method onBlockPlace.
@Listener
public void onBlockPlace(ChangeBlockEvent.Place event, @Named(NamedCause.SOURCE) Player player) {
for (Transaction<BlockSnapshot> block : event.getTransactions()) {
Optional<Location<World>> optLoc = block.getFinal().getLocation();
if (!optLoc.isPresent() || !isApplicable(optLoc.get())) {
continue;
}
Location<World> loc = optLoc.get();
BlockState finalState = block.getFinal().getState();
if (config.getDropAmplificationConfig().amplifies(finalState)) {
// Allow creative mode players to still place blocks
if (player.getGameModeData().type().get().equals(GameModes.CREATIVE)) {
continue;
}
BlockType originalType = block.getOriginal().getState().getType();
if (ore().contains(originalType)) {
continue;
}
try {
Vector3d origin = loc.getPosition();
World world = loc.getExtent();
for (int i = 0; i < 40; ++i) {
ParticleEffect effect = ParticleEffect.builder().type(ParticleTypes.MAGIC_CRITICAL_HIT).velocity(new Vector3d(Probability.getRangedRandom(-1, 1), Probability.getRangedRandom(-.7, .7), Probability.getRangedRandom(-1, 1))).quantity(1).build();
world.spawnParticles(effect, origin.add(.5, .5, .5));
}
} catch (Exception ex) {
player.sendMessage(/* ChatTypes.SYSTEM, */
Text.of(TextColors.RED, "You find yourself unable to place that block."));
}
block.setValid(false);
}
}
}
use of org.spongepowered.api.block.BlockType in project HuskyCrates-Sponge by codeHusky.
the class HuskyCrates method placeBlock.
@Listener
public void placeBlock(ChangeBlockEvent event) {
if (event.getCause().root() instanceof Player) {
Player plr = (Player) event.getCause().root();
if (event instanceof ChangeBlockEvent.Place || event instanceof ChangeBlockEvent.Break) {
BlockType t = event.getTransactions().get(0).getOriginal().getLocation().get().getBlock().getType();
Location<World> location = event.getTransactions().get(0).getOriginal().getLocation().get();
location.getBlock().toContainer().set(DataQuery.of("rock"), 1);
//location.getBlock().with()
if (validCrateBlocks.contains(t)) {
//crateUtilities.recognizeChest(event.getTransactions().get(0).getOriginal().getLocation().get());
if (event instanceof ChangeBlockEvent.Place) {
if (plr.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
Optional<Object> tt = plr.getItemInHand(HandTypes.MAIN_HAND).get().toContainer().get(DataQuery.of("UnsafeData", "crateID"));
if (tt.isPresent()) {
String crateID = tt.get().toString();
if (!plr.hasPermission("huskycrates.tester")) {
event.setCancelled(true);
return;
}
if (!crateUtilities.physicalCrates.containsKey(location))
crateUtilities.physicalCrates.put(location, new PhysicalCrate(location, crateID, this));
crateUtilities.physicalCrates.get(location).createHologram();
updatePhysicalCrates();
}
}
}
} else {
if (crateUtilities.physicalCrates.containsKey(location)) {
if (!plr.hasPermission("huskycrates.tester")) {
event.setCancelled(true);
return;
}
crateUtilities.flag = true;
crateUtilities.physicalCrates.get(location).as.remove();
crateUtilities.physicalCrates.remove(location);
updatePhysicalCrates();
}
}
}
}
}
use of org.spongepowered.api.block.BlockType in project SpongeCommon by SpongePowered.
the class SpongeParticleHelper method getBlockState.
@SuppressWarnings("deprecation")
private static int getBlockState(SpongeParticleEffect effect, Optional<BlockState> defaultBlockState) {
Optional<BlockState> blockState = effect.getOption(ParticleOptions.BLOCK_STATE);
if (blockState.isPresent()) {
return Block.getStateId((IBlockState) blockState.get());
}
Optional<ItemStackSnapshot> optSnapshot = effect.getOption(ParticleOptions.ITEM_STACK_SNAPSHOT);
if (optSnapshot.isPresent()) {
ItemStackSnapshot snapshot = optSnapshot.get();
Optional<BlockType> blockType = snapshot.getType().getBlock();
if (blockType.isPresent()) {
return Block.getStateId(((Block) blockType.get()).getStateFromMeta(((SpongeItemStackSnapshot) snapshot).getDamageValue()));
}
return 0;
}
return Block.getStateId((IBlockState) defaultBlockState.get());
}
use of org.spongepowered.api.block.BlockType in project SpongeCommon by SpongePowered.
the class BreakablePlaceableUtils method get.
public static Optional<Set<BlockType>> get(ItemStack stack, String nbtKey) {
NBTTagCompound tag = stack.getTagCompound();
if (tag == null) {
return Optional.empty();
}
NBTTagList blockIds = tag.getTagList(nbtKey, NbtDataUtil.TAG_STRING);
if (blockIds.hasNoTags()) {
return Optional.empty();
}
Set<BlockType> blockTypes = Sets.newHashSetWithExpectedSize(blockIds.tagCount());
for (int i = 0; i < blockIds.tagCount(); i++) {
Optional<BlockType> blockType = SpongeImpl.getGame().getRegistry().getType(BlockType.class, blockIds.getStringTagAt(i));
if (blockType.isPresent()) {
blockTypes.add(blockType.get());
}
}
return Optional.of(blockTypes);
}
use of org.spongepowered.api.block.BlockType in project SpongeCommon by SpongePowered.
the class MixinChunk_Collisions method allowEntityCollision.
private <T extends Entity> boolean allowEntityCollision(List<T> listToFill) {
if (this.world instanceof IMixinWorldServer) {
IMixinWorldServer spongeWorld = (IMixinWorldServer) this.world;
if (spongeWorld.isProcessingExplosion()) {
// allow explosions
return true;
}
final PhaseContext<?> phaseContext = PhaseTracker.getInstance().getCurrentContext();
LocatableBlock locatable = phaseContext.getSource(LocatableBlock.class).orElse(null);
if (locatable != null) {
BlockType blockType = locatable.getLocation().getBlockType();
IModData_Collisions spongeBlock = (IModData_Collisions) blockType;
if (spongeBlock.requiresCollisionsCacheRefresh()) {
spongeBlock.initializeCollisionState(this.world);
spongeBlock.requiresCollisionsCacheRefresh(false);
}
return !((spongeBlock.getMaxCollisions() >= 0) && (listToFill.size() >= spongeBlock.getMaxCollisions()));
}
IModData_Collisions spongeEntity = phaseContext.getSource(IModData_Collisions.class).orElse(null);
if (spongeEntity != null) {
if (spongeEntity.requiresCollisionsCacheRefresh()) {
spongeEntity.initializeCollisionState(this.world);
spongeEntity.requiresCollisionsCacheRefresh(false);
}
return !((spongeEntity.getMaxCollisions() >= 0) && (listToFill.size() >= spongeEntity.getMaxCollisions()));
}
return true;
}
return true;
}
Aggregations