use of org.spongepowered.api.block.BlockState in project Skree by Skelril.
the class BuildWorldWrapper method onBlockBreak.
@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @Named(NamedCause.SOURCE) Entity srcEnt) {
if (!isApplicable(srcEnt)) {
return;
}
List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
for (Transaction<BlockSnapshot> block : transactions) {
BlockSnapshot original = block.getOriginal();
if (original.getCreator().isPresent()) {
continue;
}
Optional<Location<World>> optLoc = original.getLocation();
if (!optLoc.isPresent()) {
continue;
}
Location<World> loc = optLoc.get();
BlockState state = original.getState();
// Prevent item dupe glitch by removing the position before subsequent breaks
markedOrePoints.remove(loc);
if (config.getDropModification().blocks(state)) {
markedOrePoints.add(loc);
}
}
}
use of org.spongepowered.api.block.BlockState in project SpongeForge by SpongePowered.
the class MixinBlockLeaves method onBreakBlock.
@Redirect(method = "breakBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;beginLeavesDecay(Lnet/minecraft/block/state/IBlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)V", remap = false))
public void onBreakBlock(Block block, IBlockState state, net.minecraft.world.World worldIn, BlockPos pos) {
if (!worldIn.isRemote) {
final PhaseTracker phaseTracker = PhaseTracker.getInstance();
final IPhaseState currentState = phaseTracker.getCurrentState();
final boolean isBlockAlready = currentState.getPhase() != TrackingPhases.BLOCK;
@Nullable PhaseContext<?> blockDecay = null;
final boolean isWorldGen = currentState.isWorldGeneration();
if (isBlockAlready && !isWorldGen) {
final LocatableBlock locatable = LocatableBlock.builder().location(new Location<World>((World) worldIn, pos.getX(), pos.getY(), pos.getZ())).state((BlockState) state).build();
blockDecay = BlockPhase.State.BLOCK_DECAY.createPhaseContext().source(locatable);
}
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame();
PhaseContext<?> context = blockDecay != null ? blockDecay.buildAndSwitch() : null) {
frame.addContext(EventContextKeys.LEAVES_DECAY, (World) worldIn);
if (SpongeCommonEventFactory.callChangeBlockEventPre((IMixinWorldServer) worldIn, pos).isCancelled()) {
return;
}
block.beginLeavesDecay(state, worldIn, pos);
}
} else {
block.beginLeavesDecay(state, worldIn, pos);
}
}
use of org.spongepowered.api.block.BlockState in project SpongeForge by SpongePowered.
the class MixinBlockLog method onBreakBlock.
@Redirect(method = "breakBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;beginLeavesDecay(Lnet/minecraft/block/state/IBlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)V", remap = false))
public void onBreakBlock(Block block, IBlockState state, net.minecraft.world.World worldIn, BlockPos pos) {
if (!worldIn.isRemote) {
if (SpongeCommonEventFactory.callChangeBlockEventPre((IMixinWorldServer) worldIn, pos).isCancelled()) {
return;
}
final PhaseTracker phaseTracker = PhaseTracker.getInstance();
final IPhaseState currentState = phaseTracker.getCurrentState();
final boolean isBlockAlready = currentState.getPhase() != TrackingPhases.BLOCK;
final boolean isWorldGen = currentState.isWorldGeneration();
if (isBlockAlready && !isWorldGen) {
final LocatableBlock locatable = LocatableBlock.builder().location(new Location<World>((World) worldIn, pos.getX(), pos.getY(), pos.getZ())).state((BlockState) state).build();
BlockPhase.State.BLOCK_DECAY.createPhaseContext().source(locatable).buildAndSwitch();
}
block.beginLeavesDecay(state, worldIn, pos);
if (isBlockAlready && !isWorldGen) {
phaseTracker.completePhase(BlockPhase.State.BLOCK_DECAY);
}
} else {
block.beginLeavesDecay(state, worldIn, pos);
}
}
use of org.spongepowered.api.block.BlockState in project SpongeForge by SpongePowered.
the class SpongeChunkGeneratorForge method checkForgeEvent.
private boolean checkForgeEvent(Populator populator, IChunkGenerator chunkProvider, int chunkX, int chunkZ, List<String> flags, Chunk chunk) {
boolean village_flag = flags.contains(WorldGenConstants.VILLAGE_FLAG);
if (populator instanceof Ore && populator instanceof WorldGenerator) {
BlockType type = ((Ore) populator).getOreBlock().getType();
GenerateMinable.EventType otype = null;
if (type.equals(BlockTypes.DIRT)) {
otype = GenerateMinable.EventType.DIRT;
} else if (type.equals(BlockTypes.GRAVEL)) {
otype = GenerateMinable.EventType.GRAVEL;
} else if (type.equals(BlockTypes.STONE)) {
BlockState state = ((Ore) populator).getOreBlock();
Optional<StoneType> stype;
if ((stype = state.get(Keys.STONE_TYPE)).isPresent()) {
StoneType stoneType = stype.get();
if (stoneType.equals(StoneTypes.DIORITE)) {
otype = GenerateMinable.EventType.DIORITE;
} else if (stoneType.equals(StoneTypes.ANDESITE)) {
otype = GenerateMinable.EventType.ANDESITE;
} else if (stoneType.equals(StoneTypes.GRANITE)) {
otype = GenerateMinable.EventType.GRANITE;
} else {
return true;
}
}
} else if (type.equals(BlockTypes.COAL_ORE)) {
otype = GenerateMinable.EventType.COAL;
} else if (type.equals(BlockTypes.IRON_ORE)) {
otype = GenerateMinable.EventType.IRON;
} else if (type.equals(BlockTypes.GOLD_ORE)) {
otype = GenerateMinable.EventType.GOLD;
} else if (type.equals(BlockTypes.REDSTONE_ORE)) {
otype = GenerateMinable.EventType.REDSTONE;
} else if (type.equals(BlockTypes.DIAMOND_ORE)) {
otype = GenerateMinable.EventType.DIAMOND;
} else if (type.equals(BlockTypes.LAPIS_ORE)) {
otype = GenerateMinable.EventType.LAPIS;
} else if (type.equals(BlockTypes.QUARTZ_ORE)) {
otype = GenerateMinable.EventType.QUARTZ;
} else if (type.equals(BlockTypes.EMERALD_ORE)) {
otype = GenerateMinable.EventType.EMERALD;
} else if (type.equals(BlockTypes.MONSTER_EGG)) {
otype = GenerateMinable.EventType.SILVERFISH;
}
return otype == null || TerrainGen.generateOre((World) chunk.getWorld(), this.rand, (WorldGenerator) populator, VecHelper.toBlockPos(chunk.getBlockMin()), otype);
}
Populate.EventType etype = this.getForgeEventTypeForPopulator(populator, chunk);
boolean populate = TerrainGen.populate(chunkProvider, (net.minecraft.world.World) chunk.getWorld(), this.rand, chunkX, chunkZ, village_flag, etype);
Decorate.EventType detype = this.getForgeDecorateEventTypeForPopulator(populator, chunk);
boolean decorate = TerrainGen.decorate((World) chunk.getWorld(), this.rand, VecHelper.toBlockPos(chunk.getBlockMin()), detype);
// TODO May need to separate this..
return populate && decorate;
}
use of org.spongepowered.api.block.BlockState in project AdamantineShield by Karanum.
the class RollbackManager method performAddition.
// TODO: Set proper causes for block changes caused by rollback/undo
private void performAddition(LookupLine line) {
World w = Sponge.getServer().getWorld(line.getWorld()).orElse(null);
if (w == null)
return;
if (line.getTarget() instanceof ItemType) {
Optional<TileEntity> te = w.getTileEntity(line.getPos());
if (te.isPresent() && te.get() instanceof TileEntityCarrier) {
TileEntityCarrier c = (TileEntityCarrier) te.get();
Inventory i = c.getInventory();
ItemType type = (ItemType) line.getTarget();
ItemStack stack = ItemStack.builder().fromContainer(line.getDataAsView()).itemType(type).quantity(line.getCount()).build();
Inventory slot = i.query(QueryOperationTypes.INVENTORY_PROPERTY.of(SlotIndex.of(line.getSlot())));
slot.set(stack);
}
} else if (line.getTarget() instanceof BlockType) {
BlockState block = null;
if (line.getDataAsView() == null) {
block = BlockState.builder().blockType((BlockType) line.getTarget()).build();
w.setBlock(line.getPos(), block);
} else {
DataView blockData = line.getDataAsView();
DataView blockState = blockData.getView(DataQuery.of("BlockState")).orElse(null);
block = BlockState.builder().build(blockState).orElse(null);
if (block != null)
w.setBlock(line.getPos(), block);
}
}
}
Aggregations