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;
}
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);
}
});
}
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);
}
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);
}
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();
}
}
}
Aggregations