Search in sources :

Example 96 with BlockState

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);
        }
    }
}
Also used : BlockState(org.spongepowered.api.block.BlockState) Transaction(org.spongepowered.api.data.Transaction) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 97 with BlockState

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);
    }
}
Also used : PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) BlockState(org.spongepowered.api.block.BlockState) IBlockState(net.minecraft.block.state.IBlockState) CauseStackManager(org.spongepowered.api.event.CauseStackManager) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState) LocatableBlock(org.spongepowered.api.world.LocatableBlock) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) World(org.spongepowered.api.world.World) Nullable(javax.annotation.Nullable) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 98 with BlockState

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);
    }
}
Also used : PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) BlockState(org.spongepowered.api.block.BlockState) IBlockState(net.minecraft.block.state.IBlockState) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) LocatableBlock(org.spongepowered.api.world.LocatableBlock) World(org.spongepowered.api.world.World) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 99 with BlockState

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;
}
Also used : WorldGenerator(net.minecraft.world.gen.feature.WorldGenerator) Ore(org.spongepowered.api.world.gen.populator.Ore) StoneType(org.spongepowered.api.data.type.StoneType) Decorate(net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate) World(net.minecraft.world.World) BlockState(org.spongepowered.api.block.BlockState) BlockType(org.spongepowered.api.block.BlockType) Populate(net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate) GenerateMinable(net.minecraftforge.event.terraingen.OreGenEvent.GenerateMinable)

Example 100 with BlockState

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);
        }
    }
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) DataView(org.spongepowered.api.data.DataView) BlockState(org.spongepowered.api.block.BlockState) BlockType(org.spongepowered.api.block.BlockType) ItemType(org.spongepowered.api.item.ItemType) TileEntityCarrier(org.spongepowered.api.block.tileentity.carrier.TileEntityCarrier) World(org.spongepowered.api.world.World) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory)

Aggregations

BlockState (org.spongepowered.api.block.BlockState)133 World (org.spongepowered.api.world.World)39 IBlockState (net.minecraft.block.state.IBlockState)29 BlockType (org.spongepowered.api.block.BlockType)27 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)22 Direction (org.spongepowered.api.util.Direction)21 Optional (java.util.Optional)20 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)20 Vector3i (com.flowpowered.math.vector.Vector3i)19 Location (org.spongepowered.api.world.Location)18 ItemStack (org.spongepowered.api.item.inventory.ItemStack)17 LocatableBlock (org.spongepowered.api.world.LocatableBlock)14 Sponge (org.spongepowered.api.Sponge)13 ItemType (org.spongepowered.api.item.ItemType)13 ArrayList (java.util.ArrayList)12 Player (org.spongepowered.api.entity.living.player.Player)12 List (java.util.List)11 InvalidDataException (org.spongepowered.api.data.persistence.InvalidDataException)11 Vector3d (com.flowpowered.math.vector.Vector3d)10 Listener (org.spongepowered.api.event.Listener)10