Search in sources :

Example 31 with BlockState

use of net.minecraft.world.level.block.state.BlockState in project SpongeCommon by SpongePowered.

the class WorldPipeline method processEffects.

public boolean processEffects(final PhaseContext<?> context, final BlockState currentState, final BlockState newProposedState, final BlockPos pos, @Nullable final Entity destroyer, final SpongeBlockChangeFlag flag, final int limit) {
    if (this.worldEffects.isEmpty()) {
        return false;
    }
    final ServerLevel serverWorld = Objects.requireNonNull(this.serverWorld).get();
    // Keep track of the existing block entity prior to processing the chunk pipeline
    // and the reasoning is that in several cases where the block entity that is being removed
    // will no longer be available. This could be avoided by having the "previous cursor" returned
    // from ChunkPipeline, but alas.... that's a refactor for another time.
    @Nullable final BlockEntity existing = this.chunkSupplier.get().getBlockEntity(pos, LevelChunk.EntityCreationType.CHECK);
    // We have to get the "old state" from
    @Nullable final BlockState oldState = this.chunkPipeline.processChange(context, currentState, newProposedState, pos, limit);
    if (oldState == null) {
        return false;
    }
    final int oldOpacity = oldState.getLightBlock(serverWorld, pos);
    PipelineCursor formerState = new PipelineCursor(oldState, oldOpacity, pos, existing, destroyer, limit);
    for (final ResultingTransactionBySideEffect effect : this.worldEffects) {
        try (final EffectTransactor ignored = context.getTransactor().pushEffect(effect)) {
            final EffectResult result = effect.effect.processSideEffect(this, formerState, newProposedState, flag, limit);
            if (result.hasResult) {
                return result.resultingState != null;
            }
            if (formerState.drops.isEmpty() && !result.drops.isEmpty()) {
                formerState = new PipelineCursor(oldState, oldOpacity, pos, existing, formerState.destroyer, result.drops, limit);
            }
        }
    }
    // if we've gotten here, means something is wrong, we didn't build our effects right.
    return false;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) BlockState(net.minecraft.world.level.block.state.BlockState) EffectResult(org.spongepowered.common.event.tracking.context.transaction.effect.EffectResult) ResultingTransactionBySideEffect(org.spongepowered.common.event.tracking.context.transaction.ResultingTransactionBySideEffect) EffectTransactor(org.spongepowered.common.event.tracking.context.transaction.EffectTransactor) Nullable(org.checkerframework.checker.nullness.qual.Nullable) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 32 with BlockState

use of net.minecraft.world.level.block.state.BlockState in project SpongeCommon by SpongePowered.

the class ExplosionMixin_Tracker method finalizeExplosion.

/**
 * @author gabziou
 * @author zidane
 * @reason Run explosion logic through tracking
 */
@Overwrite
public void finalizeExplosion(final boolean spawnParticles) {
    // Sponge Start - In Sponge, we no longer call doExplosionB client-side (kills client perf)
    if (this.level.isClientSide) {
        return;
    }
    // Sponge End
    // Sponge Start - Send the sound packet down. We must do this as we do not call doExplosionB client-side
    this.level.playSound(null, this.x, this.y, this.z, SoundEvents.GENERIC_EXPLODE, SoundSource.BLOCKS, 4.0F, (1.0F + (this.level.random.nextFloat() - this.level.random.nextFloat()) * 0.2F) * 0.7F);
    // Sponge End
    final boolean flag = this.blockInteraction != net.minecraft.world.level.Explosion.BlockInteraction.NONE;
    if (spawnParticles) {
        if (!(this.radius < 2.0F) && (flag || ((ExplosionBridge) this).bridge$getShouldDamageBlocks())) {
            // hundreds of explosions at once
            if (this.level instanceof ServerLevel) {
                ((ServerLevel) this.level).sendParticles(ParticleTypes.EXPLOSION_EMITTER, this.x, this.y, this.z, 1, 0, 0, 0, 0.1D);
            } else {
                this.level.addParticle(ParticleTypes.EXPLOSION_EMITTER, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
            }
        // Sponge End
        } else {
            // hundreds of explosions at once
            if (this.level instanceof ServerLevel) {
                ((ServerLevel) this.level).sendParticles(ParticleTypes.EXPLOSION, this.x, this.y, this.z, 1, 0, 0, 0, 0.1D);
            } else {
                this.level.addParticle(ParticleTypes.EXPLOSION, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
            }
        // Sponge End
        }
    }
    if (flag) {
        // Sponge Start - Forward changes through a WorldPipeline to associate side effects
        // Vanilla - uses a list of itemstacks to do a bunch of pre-merging
        // ObjectArrayList<Pair<ItemStack, BlockPos>> objectarraylist = new ObjectArrayList<>();
        Collections.shuffle(this.toBlow, this.level.random);
        for (final BlockPos blockpos : this.toBlow) {
            final BlockState blockstate = this.level.getBlockState(blockpos);
            // Block block = blockstate.getBlock(); // Sponge - we don't use this
            if (!blockstate.isAir()) {
                final BlockPos blockpos1 = blockpos.immutable();
                this.level.getProfiler().push("explosion_blocks");
                // Sponge - All of this is forwarded to the effects
                // if (block.canDropFromExplosion(this) && this.level instanceof ServerLevel) {
                // BlockEntity var6 = block.isEntityBlock() ? this.level.getBlockEntity(blockpos) : null;
                // LootContext.Builder lootcontext$builder = (new LootContext.Builder((ServerLevel)this.level)).withRandom(this.level.rand).withParameter(
                // LootParameters.ORIGIN, Vec3.atCenterOf(blockpos)).withParameter(LootParameters.TOOL, ItemStack.EMPTY).withNullableParameter(LootParameters.BLOCK_ENTITY, var6).withNullableParameter(LootParameters.THIS_ENTITY, this.source);
                // if (this.blockInteraction == Explosion.BlockInteraction.DESTROY) {
                // lootcontext$builder.withParameter(LootParameters.EXPLOSION_RADIUS, this.radius);
                // }
                // var3.getDrops(var7).forEach((param2) -> addBlockDrops(var1, param2, var5));
                // }
                // this.level.setBlock(blockpos, Blocks.AIR.defaultState(), 3);
                // block.onExplosionDestroy(this.world, blockpos, this);
                final PhaseContext<@NonNull ?> context = PhaseTracker.getInstance().getPhaseContext();
                ((TrackedWorldBridge) this.level).bridge$startBlockChange(blockpos1, Blocks.AIR.defaultBlockState(), 3).ifPresent(builder -> {
                    final WorldPipeline build = builder.addEffect(AddBlockLootDropsEffect.getInstance()).addEffect(ExplodeBlockEffect.getInstance()).addEffect(SpawnDestructBlocksEffect.getInstance()).addEffect(WorldBlockChangeCompleteEffect.getInstance()).build();
                    build.processEffects(context, blockstate, Blocks.AIR.defaultBlockState(), blockpos1, null, BlockChangeFlagManager.fromNativeInt(3), Constants.World.DEFAULT_BLOCK_CHANGE_LIMIT);
                });
                // Sponge End
                this.level.getProfiler().pop();
            }
        }
    // Sponge Start - This is built into the SpawnDestructBlocksEffect
    // for(Pair<ItemStack, BlockPos> var8 : objectarraylist) {
    // Block.popResource(this.level, var8.getSecond(), var8.getFirst());
    // }
    // Sponge End
    }
    if (this.fire) {
        for (final BlockPos blockpos2 : this.toBlow) {
            if (this.random.nextInt(3) == 0 && this.level.getBlockState(blockpos2).isAir() && this.level.getBlockState(blockpos2.below()).isSolidRender(this.level, blockpos2.below())) {
                this.level.setBlockAndUpdate(blockpos2, BaseFireBlock.getState(this.level, blockpos2));
            }
        }
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos) WorldPipeline(org.spongepowered.common.event.tracking.context.transaction.pipeline.WorldPipeline) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 33 with BlockState

use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.

the class MachineRenderer method render.

@Override
public void render(T te, float partialTicks, PoseStack stack, MultiBufferSource buffer, int combinedLightIn, int combinedOverlayIn) {
    stack.pushPose();
    stack.translate(0.5f, 1.5f, 0.5f);
    stack.mulPose(Vector3f.XP.rotationDegrees(180));
    if (te == null || te.getLevel() == null) {
        stack.mulPose(Vector3f.YP.rotationDegrees(-90));
    } else {
        BlockState state = te.getLevel().getBlockState(te.getBlockPos());
        Direction facing;
        if (state.getBlock() != this.block) {
            facing = Direction.NORTH;
        } else {
            facing = te.getDirection(state);
        }
        stack.mulPose(Vector3f.YP.rotationDegrees(facing.toYRot() + 90));
    }
    if (te != null && te.isActive()) {
        animationTransform(te, stack, partialTicks);
    }
    // TropicraftRenderUtils.bindTextureTE(model.getTexture(te));
    // model.renderAsBlock(te);
    // Get light above, since block is solid
    TropicraftRenderUtils.renderModel(getMaterial(), model, stack, buffer, combinedLightIn, combinedOverlayIn);
    if (te != null) {
        renderIngredients(te, stack, buffer, combinedLightIn, combinedOverlayIn);
    }
    // GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
    stack.popPose();
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Direction(net.minecraft.core.Direction)

Example 34 with BlockState

use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.

the class BoardwalkBlock method connectsTo.

private boolean connectsTo(LevelAccessor world, BlockPos pos, Direction.Axis axis, Direction.AxisDirection direction) {
    BlockPos connectPos = pos.relative(Direction.fromAxisAndDirection(axis, direction));
    BlockState connectState = world.getBlockState(connectPos);
    return connectState.is(this) && connectState.getValue(TYPE).isShort();
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos)

Example 35 with BlockState

use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.

the class BoardwalkBlock method getStateForPlacement.

@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
    Level world = context.getLevel();
    BlockPos pos = context.getClickedPos();
    boolean tall = context.getClickLocation().y - pos.getY() > 0.5;
    BlockState state = this.defaultBlockState().setValue(AXIS, context.getHorizontalDirection().getAxis()).setValue(TYPE, tall ? Type.TALL : Type.SHORT).setValue(WATERLOGGED, world.getFluidState(pos).getType() == Fluids.WATER);
    state = this.applyConnections(state, world, pos);
    return state;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos)

Aggregations

BlockState (net.minecraft.world.level.block.state.BlockState)141 BlockPos (net.minecraft.core.BlockPos)75 Direction (net.minecraft.core.Direction)18 Level (net.minecraft.world.level.Level)14 Block (net.minecraft.world.level.block.Block)14 ArrayList (java.util.ArrayList)10 ServerLevel (net.minecraft.server.level.ServerLevel)10 SoundType (net.minecraft.world.level.block.SoundType)10 Vec3 (net.minecraft.world.phys.Vec3)10 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)9 Random (java.util.Random)8 ItemStack (net.minecraft.world.item.ItemStack)7 FluidState (net.minecraft.world.level.material.FluidState)7 AABB (net.minecraft.world.phys.AABB)6 BuildBlock (com.wuest.prefab.structures.base.BuildBlock)5 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)5 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)5 LocationTag (com.denizenscript.denizen.objects.LocationTag)4 FakeBlock (com.denizenscript.denizen.utilities.blocks.FakeBlock)4 HashMap (java.util.HashMap)4