Search in sources :

Example 1 with MovementContext

use of com.simibubi.create.content.contraptions.components.structureMovement.MovementContext in project Create by Creators-of-Create.

the class ContraptionInstanceManager method createActor.

@Nullable
public ActorInstance createActor(Pair<StructureBlockInfo, MovementContext> actor) {
    StructureBlockInfo blockInfo = actor.getLeft();
    MovementContext context = actor.getRight();
    MovementBehaviour movementBehaviour = AllMovementBehaviours.of(blockInfo.state);
    if (movementBehaviour != null && movementBehaviour.hasSpecialInstancedRendering()) {
        ActorInstance instance = movementBehaviour.createInstance(materialManager, renderWorld, context);
        actors.add(instance);
        return instance;
    }
    return null;
}
Also used : StructureBlockInfo(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo) MovementContext(com.simibubi.create.content.contraptions.components.structureMovement.MovementContext) MovementBehaviour(com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour) Nullable(javax.annotation.Nullable)

Example 2 with MovementContext

use of com.simibubi.create.content.contraptions.components.structureMovement.MovementContext in project Create by Creators-of-Create.

the class IMovedDispenseItemBehaviour method init.

static void init() {
    MovedProjectileDispenserBehaviour movedPotionDispenseItemBehaviour = new MovedProjectileDispenserBehaviour() {

        @Override
        protected Projectile getProjectileEntity(Level world, double x, double y, double z, ItemStack itemStack) {
            return Util.make(new ThrownPotion(world, x, y, z), (p_218411_1_) -> p_218411_1_.setItem(itemStack));
        }

        protected float getProjectileInaccuracy() {
            return super.getProjectileInaccuracy() * 0.5F;
        }

        protected float getProjectileVelocity() {
            return super.getProjectileVelocity() * .5F;
        }
    };
    DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.SPLASH_POTION, movedPotionDispenseItemBehaviour);
    DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.LINGERING_POTION, movedPotionDispenseItemBehaviour);
    DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.TNT, new MovedDefaultDispenseItemBehaviour() {

        @Override
        protected ItemStack dispenseStack(ItemStack itemStack, MovementContext context, BlockPos pos, Vec3 facing) {
            double x = pos.getX() + facing.x * .7 + .5;
            double y = pos.getY() + facing.y * .7 + .5;
            double z = pos.getZ() + facing.z * .7 + .5;
            PrimedTnt tntentity = new PrimedTnt(context.world, x, y, z, null);
            tntentity.push(context.motion.x, context.motion.y, context.motion.z);
            context.world.addFreshEntity(tntentity);
            context.world.playSound(null, tntentity.getX(), tntentity.getY(), tntentity.getZ(), SoundEvents.TNT_PRIMED, SoundSource.BLOCKS, 1.0F, 1.0F);
            itemStack.shrink(1);
            return itemStack;
        }
    });
    DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.FIREWORK_ROCKET, new MovedDefaultDispenseItemBehaviour() {

        @Override
        protected ItemStack dispenseStack(ItemStack itemStack, MovementContext context, BlockPos pos, Vec3 facing) {
            double x = pos.getX() + facing.x * .7 + .5;
            double y = pos.getY() + facing.y * .7 + .5;
            double z = pos.getZ() + facing.z * .7 + .5;
            FireworkRocketEntity fireworkrocketentity = new FireworkRocketEntity(context.world, itemStack, x, y, z, true);
            fireworkrocketentity.shoot(facing.x, facing.y, facing.z, 0.5F, 1.0F);
            context.world.addFreshEntity(fireworkrocketentity);
            itemStack.shrink(1);
            return itemStack;
        }

        @Override
        protected void playDispenseSound(LevelAccessor world, BlockPos pos) {
            world.levelEvent(1004, pos, 0);
        }
    });
    DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.FIRE_CHARGE, new MovedDefaultDispenseItemBehaviour() {

        @Override
        protected void playDispenseSound(LevelAccessor world, BlockPos pos) {
            world.levelEvent(1018, pos, 0);
        }

        @Override
        protected ItemStack dispenseStack(ItemStack itemStack, MovementContext context, BlockPos pos, Vec3 facing) {
            Random random = context.world.random;
            double x = pos.getX() + facing.x * .7 + .5;
            double y = pos.getY() + facing.y * .7 + .5;
            double z = pos.getZ() + facing.z * .7 + .5;
            context.world.addFreshEntity(Util.make(new SmallFireball(context.world, x, y, z, random.nextGaussian() * 0.05D + facing.x + context.motion.x, random.nextGaussian() * 0.05D + facing.y + context.motion.y, random.nextGaussian() * 0.05D + facing.z + context.motion.z), (p_229425_1_) -> p_229425_1_.setItem(itemStack)));
            itemStack.shrink(1);
            return itemStack;
        }
    });
    DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.GLASS_BOTTLE, new MovedOptionalDispenseBehaviour() {

        @Override
        protected ItemStack dispenseStack(ItemStack itemStack, MovementContext context, BlockPos pos, Vec3 facing) {
            this.successful = false;
            BlockPos interactAt = pos.relative(getClosestFacingDirection(facing));
            BlockState state = context.world.getBlockState(interactAt);
            Block block = state.getBlock();
            if (state.is(BlockTags.BEEHIVES) && state.getValue(BeehiveBlock.HONEY_LEVEL) >= 5) {
                ((BeehiveBlock) block).releaseBeesAndResetHoneyLevel(context.world, state, interactAt, null, BeehiveBlockEntity.BeeReleaseStatus.BEE_RELEASED);
                this.successful = true;
                return placeItemInInventory(itemStack, new ItemStack(Items.HONEY_BOTTLE), context, pos, facing);
            } else if (context.world.getFluidState(interactAt).is(FluidTags.WATER)) {
                this.successful = true;
                return placeItemInInventory(itemStack, PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER), context, pos, facing);
            } else {
                return super.dispenseStack(itemStack, context, pos, facing);
            }
        }
    });
    DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.BUCKET, new MovedDefaultDispenseItemBehaviour() {

        @Override
        protected ItemStack dispenseStack(ItemStack itemStack, MovementContext context, BlockPos pos, Vec3 facing) {
            BlockPos interactAt = pos.relative(getClosestFacingDirection(facing));
            BlockState state = context.world.getBlockState(interactAt);
            Block block = state.getBlock();
            if (block instanceof BucketPickup) {
                ItemStack bucket = ((BucketPickup) block).pickupBlock(context.world, interactAt, state);
                return placeItemInInventory(itemStack, bucket, context, pos, facing);
            }
            return super.dispenseStack(itemStack, context, pos, facing);
        }
    });
}
Also used : PrimedTnt(net.minecraft.world.entity.item.PrimedTnt) LevelAccessor(net.minecraft.world.level.LevelAccessor) FireworkRocketEntity(net.minecraft.world.entity.projectile.FireworkRocketEntity) BucketPickup(net.minecraft.world.level.block.BucketPickup) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) Vec3(net.minecraft.world.phys.Vec3) ThrownPotion(net.minecraft.world.entity.projectile.ThrownPotion) BeehiveBlock(net.minecraft.world.level.block.BeehiveBlock) Block(net.minecraft.world.level.block.Block) ServerLevel(net.minecraft.server.level.ServerLevel) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) SmallFireball(net.minecraft.world.entity.projectile.SmallFireball) ItemStack(net.minecraft.world.item.ItemStack) MovementContext(com.simibubi.create.content.contraptions.components.structureMovement.MovementContext)

Example 3 with MovementContext

use of com.simibubi.create.content.contraptions.components.structureMovement.MovementContext in project Create by Creators-of-Create.

the class BlockBreakingMovementBehaviour method tickBreaker.

public void tickBreaker(MovementContext context) {
    CompoundTag data = context.data;
    if (context.world.isClientSide)
        return;
    if (!data.contains("BreakingPos"))
        return;
    if (context.relativeMotion.equals(Vec3.ZERO)) {
        context.stall = false;
        return;
    }
    int ticksUntilNextProgress = data.getInt("TicksUntilNextProgress");
    if (ticksUntilNextProgress-- > 0) {
        data.putInt("TicksUntilNextProgress", ticksUntilNextProgress);
        return;
    }
    Level world = context.world;
    BlockPos breakingPos = NbtUtils.readBlockPos(data.getCompound("BreakingPos"));
    int destroyProgress = data.getInt("Progress");
    int id = data.getInt("BreakerId");
    BlockState stateToBreak = world.getBlockState(breakingPos);
    float blockHardness = stateToBreak.getDestroySpeed(world, breakingPos);
    if (!canBreak(world, breakingPos, stateToBreak)) {
        if (destroyProgress != 0) {
            destroyProgress = 0;
            data.remove("Progress");
            data.remove("TicksUntilNextProgress");
            data.remove("BreakingPos");
            world.destroyBlockProgress(id, breakingPos, -1);
        }
        context.stall = false;
        return;
    }
    float breakSpeed = Mth.clamp(Math.abs(context.getAnimationSpeed()) / 500f, 1 / 128f, 16f);
    destroyProgress += Mth.clamp((int) (breakSpeed / blockHardness), 1, 10 - destroyProgress);
    world.playSound(null, breakingPos, stateToBreak.getSoundType().getHitSound(), SoundSource.NEUTRAL, .25f, 1);
    if (destroyProgress >= 10) {
        world.destroyBlockProgress(id, breakingPos, -1);
        // break falling blocks from top to bottom
        BlockPos ogPos = breakingPos;
        BlockState stateAbove = world.getBlockState(breakingPos.above());
        while (stateAbove.getBlock() instanceof FallingBlock) {
            breakingPos = breakingPos.above();
            stateAbove = world.getBlockState(breakingPos.above());
        }
        stateToBreak = world.getBlockState(breakingPos);
        context.stall = false;
        if (shouldDestroyStartBlock(stateToBreak))
            BlockHelper.destroyBlock(context.world, breakingPos, 1f, stack -> this.dropItem(context, stack));
        onBlockBroken(context, ogPos, stateToBreak);
        ticksUntilNextProgress = -1;
        data.remove("Progress");
        data.remove("TicksUntilNextProgress");
        data.remove("BreakingPos");
        return;
    }
    ticksUntilNextProgress = (int) (blockHardness / breakSpeed);
    world.destroyBlockProgress(id, breakingPos, (int) destroyProgress);
    data.putInt("TicksUntilNextProgress", ticksUntilNextProgress);
    data.putInt("Progress", destroyProgress);
}
Also used : FallingBlock(net.minecraft.world.level.block.FallingBlock) SoundSource(net.minecraft.sounds.SoundSource) NbtUtils(net.minecraft.nbt.NbtUtils) AABB(net.minecraft.world.phys.AABB) FallingBlock(net.minecraft.world.level.block.FallingBlock) MovementBehaviour(com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour) AbstractMinecart(net.minecraft.world.entity.vehicle.AbstractMinecart) BlockState(net.minecraft.world.level.block.state.BlockState) Player(net.minecraft.world.entity.player.Player) BlockHelper(com.simibubi.create.foundation.utility.BlockHelper) CompoundTag(net.minecraft.nbt.CompoundTag) Entity(net.minecraft.world.entity.Entity) BlockPos(net.minecraft.core.BlockPos) ItemEntity(net.minecraft.world.entity.item.ItemEntity) Vec3(net.minecraft.world.phys.Vec3) DamageSource(net.minecraft.world.damagesource.DamageSource) MovementContext(com.simibubi.create.content.contraptions.components.structureMovement.MovementContext) Level(net.minecraft.world.level.Level) Mth(net.minecraft.util.Mth) AbstractContraptionEntity(com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity) BlockState(net.minecraft.world.level.block.state.BlockState) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 4 with MovementContext

use of com.simibubi.create.content.contraptions.components.structureMovement.MovementContext in project FrostedHeart by TeamMoegMC.

the class MixinBlockBreakingMovementBehaviour method tickBreaker.

/**
 * @author khjxiaogu
 * @reason further repair breaking speed
 */
@Overwrite(remap = false)
public void tickBreaker(MovementContext context) {
    CompoundNBT data = context.data;
    if (context.world.isRemote)
        return;
    if (!data.contains("BreakingPos"))
        return;
    if (context.relativeMotion.equals(Vector3d.ZERO)) {
        context.stall = false;
        return;
    }
    int ticksUntilNextProgress = data.getInt("TicksUntilNextProgress");
    if (ticksUntilNextProgress-- > 0) {
        data.putInt("TicksUntilNextProgress", ticksUntilNextProgress);
        return;
    }
    World world = context.world;
    BlockPos breakingPos = NBTUtil.readBlockPos(data.getCompound("BreakingPos"));
    int destroyProgress = data.getInt("Progress");
    int id = data.getInt("BreakerId");
    BlockState stateToBreak = world.getBlockState(breakingPos);
    float blockHardness = stateToBreak.getBlockHardness(world, breakingPos);
    if (!canBreak(world, breakingPos, stateToBreak)) {
        if (destroyProgress != 0) {
            destroyProgress = 0;
            data.remove("Progress");
            data.remove("TicksUntilNextProgress");
            data.remove("BreakingPos");
            world.sendBlockBreakProgress(id, breakingPos, -1);
        }
        context.stall = false;
        return;
    }
    float breakSpeed;
    if (context.contraption instanceof ISpeedContraption)
        breakSpeed = MathHelper.clamp(Math.abs(((ISpeedContraption) context.contraption).getSpeed()) * 10, 2, 16000f);
    else
        breakSpeed = MathHelper.clamp(Math.abs(context.getAnimationSpeed()) / 500f, 1 / 128f, 16f);
    destroyProgress += MathHelper.clamp((int) (breakSpeed / blockHardness), 1, 10000 - destroyProgress);
    world.playSound(null, breakingPos, stateToBreak.getSoundType().getHitSound(), SoundCategory.NEUTRAL, .25f, 1);
    if (destroyProgress >= 10000) {
        world.sendBlockBreakProgress(id, breakingPos, -1);
        // break falling blocks from top to bottom
        BlockPos ogPos = breakingPos;
        BlockState stateAbove = world.getBlockState(breakingPos.up());
        while (stateAbove.getBlock() instanceof FallingBlock) {
            breakingPos = breakingPos.up();
            stateAbove = world.getBlockState(breakingPos.up());
        }
        stateToBreak = world.getBlockState(breakingPos);
        context.stall = false;
        if (shouldDestroyStartBlock(stateToBreak))
            BlockHelper.destroyBlock(context.world, breakingPos, 1f, stack -> this.dropItem(context, stack));
        onBlockBroken(context, ogPos, stateToBreak);
        ticksUntilNextProgress = -1;
        data.remove("Progress");
        data.remove("TicksUntilNextProgress");
        data.remove("BreakingPos");
        return;
    }
    ticksUntilNextProgress = (int) (blockHardness / breakSpeed);
    world.sendBlockBreakProgress(id, breakingPos, MathHelper.clamp((int) (destroyProgress / 1000), 1, 10));
    data.putInt("TicksUntilNextProgress", ticksUntilNextProgress);
    data.putInt("Progress", destroyProgress);
}
Also used : FallingBlock(net.minecraft.block.FallingBlock) World(net.minecraft.world.World) MovementBehaviour(com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour) ISpeedContraption(com.teammoeg.frostedheart.util.ISpeedContraption) CompoundNBT(net.minecraft.nbt.CompoundNBT) BlockPos(net.minecraft.util.math.BlockPos) Overwrite(org.spongepowered.asm.mixin.Overwrite) BlockHelper(com.simibubi.create.foundation.utility.BlockHelper) Vector3d(net.minecraft.util.math.vector.Vector3d) Mixin(org.spongepowered.asm.mixin.Mixin) FallingBlock(net.minecraft.block.FallingBlock) MathHelper(net.minecraft.util.math.MathHelper) BlockBreakingMovementBehaviour(com.simibubi.create.content.contraptions.components.actors.BlockBreakingMovementBehaviour) Shadow(org.spongepowered.asm.mixin.Shadow) MovementContext(com.simibubi.create.content.contraptions.components.structureMovement.MovementContext) BlockState(net.minecraft.block.BlockState) NBTUtil(net.minecraft.nbt.NBTUtil) SoundCategory(net.minecraft.util.SoundCategory) BlockState(net.minecraft.block.BlockState) CompoundNBT(net.minecraft.nbt.CompoundNBT) ISpeedContraption(com.teammoeg.frostedheart.util.ISpeedContraption) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 5 with MovementContext

use of com.simibubi.create.content.contraptions.components.structureMovement.MovementContext in project Create by Creators-of-Create.

the class ContraptionRenderDispatcher method renderActors.

protected static void renderActors(Level world, VirtualRenderWorld renderWorld, Contraption c, ContraptionMatrices matrices, MultiBufferSource buffer) {
    PoseStack m = matrices.getModel();
    for (Pair<StructureTemplate.StructureBlockInfo, MovementContext> actor : c.getActors()) {
        MovementContext context = actor.getRight();
        if (context == null)
            continue;
        if (context.world == null)
            context.world = world;
        StructureTemplate.StructureBlockInfo blockInfo = actor.getLeft();
        MovementBehaviour movementBehaviour = AllMovementBehaviours.of(blockInfo.state);
        if (movementBehaviour != null) {
            m.pushPose();
            TransformStack.cast(m).translate(blockInfo.pos);
            movementBehaviour.renderInContraption(context, renderWorld, matrices, buffer);
            m.popPose();
        }
    }
}
Also used : PoseStack(com.mojang.blaze3d.vertex.PoseStack) StructureTemplate(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate) MovementContext(com.simibubi.create.content.contraptions.components.structureMovement.MovementContext) MovementBehaviour(com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour)

Aggregations

MovementContext (com.simibubi.create.content.contraptions.components.structureMovement.MovementContext)8 MovementBehaviour (com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour)5 BlockPos (net.minecraft.core.BlockPos)4 ServerLevel (net.minecraft.server.level.ServerLevel)4 ItemStack (net.minecraft.world.item.ItemStack)4 Vec3 (net.minecraft.world.phys.Vec3)4 BlockHelper (com.simibubi.create.foundation.utility.BlockHelper)3 Level (net.minecraft.world.level.Level)3 AbstractContraptionEntity (com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity)2 Nullable (javax.annotation.Nullable)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 Entity (net.minecraft.world.entity.Entity)2 FireworkRocketEntity (net.minecraft.world.entity.projectile.FireworkRocketEntity)2 BlockState (net.minecraft.world.level.block.state.BlockState)2 MaterialManager (com.jozufozu.flywheel.api.MaterialManager)1 Backend (com.jozufozu.flywheel.backend.Backend)1 VirtualRenderWorld (com.jozufozu.flywheel.core.virtual.VirtualRenderWorld)1 PoseStack (com.mojang.blaze3d.vertex.PoseStack)1 AllBlocks (com.simibubi.create.AllBlocks)1 AllItems (com.simibubi.create.AllItems)1