use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create by Creators-of-Create.
the class GantryShaftBlock method neighborChanged.
@Override
public void neighborChanged(BlockState state, Level worldIn, BlockPos pos, Block p_220069_4_, BlockPos p_220069_5_, boolean p_220069_6_) {
if (worldIn.isClientSide)
return;
boolean previouslyPowered = state.getValue(POWERED);
// shouldBePowered(state, worldIn, pos);
boolean shouldPower = worldIn.hasNeighborSignal(pos);
if (!previouslyPowered && !shouldPower && shouldBePowered(state, worldIn, pos)) {
worldIn.setBlock(pos, state.setValue(POWERED, true), 3);
return;
}
if (previouslyPowered == shouldPower)
return;
// Collect affected gantry shafts
List<BlockPos> toUpdate = new ArrayList<>();
Direction facing = state.getValue(FACING);
Axis axis = facing.getAxis();
for (Direction d : Iterate.directionsInAxis(axis)) {
BlockPos currentPos = pos.relative(d);
while (true) {
if (!worldIn.isLoaded(currentPos))
break;
BlockState currentState = worldIn.getBlockState(currentPos);
if (!(currentState.getBlock() instanceof GantryShaftBlock))
break;
if (currentState.getValue(FACING) != facing)
break;
if (!shouldPower && currentState.getValue(POWERED) && worldIn.hasNeighborSignal(currentPos))
return;
if (currentState.getValue(POWERED) == shouldPower)
break;
toUpdate.add(currentPos);
currentPos = currentPos.relative(d);
}
}
toUpdate.add(pos);
for (BlockPos blockPos : toUpdate) {
BlockState blockState = worldIn.getBlockState(blockPos);
BlockEntity te = worldIn.getBlockEntity(blockPos);
if (te instanceof KineticTileEntity)
((KineticTileEntity) te).detachKinetics();
if (blockState.getBlock() instanceof GantryShaftBlock)
worldIn.setBlock(blockPos, blockState.setValue(POWERED, shouldPower), 2);
}
}
use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create by Creators-of-Create.
the class TurntableBlock method entityInside.
@Override
public void entityInside(BlockState state, Level worldIn, BlockPos pos, Entity e) {
if (!e.isOnGround())
return;
if (e.getDeltaMovement().y > 0)
return;
if (e.getY() < pos.getY() + .5f)
return;
withTileEntityDo(worldIn, pos, te -> {
float speed = ((KineticTileEntity) te).getSpeed() * 3 / 10;
if (speed == 0)
return;
Level world = e.getCommandSenderWorld();
if (world.isClientSide && (e instanceof Player)) {
if (worldIn.getBlockState(e.blockPosition()) != state) {
Vec3 origin = VecHelper.getCenterOf(pos);
Vec3 offset = e.position().subtract(origin);
offset = VecHelper.rotate(offset, Mth.clamp(speed, -16, 16) / 1f, Axis.Y);
Vec3 movement = origin.add(offset).subtract(e.position());
e.setDeltaMovement(e.getDeltaMovement().add(movement));
e.hurtMarked = true;
}
}
if ((e instanceof Player))
return;
if (world.isClientSide)
return;
if ((e instanceof LivingEntity)) {
float diff = e.getYHeadRot() - speed;
((LivingEntity) e).setNoActionTime(20);
e.setYBodyRot(diff);
e.setYHeadRot(diff);
e.setOnGround(false);
e.hurtMarked = true;
}
e.setYRot(e.getYRot() - speed);
});
}
use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create by Creators-of-Create.
the class BlockHelper method placeSchematicBlock.
public static void placeSchematicBlock(Level world, BlockState state, BlockPos target, ItemStack stack, @Nullable CompoundTag data) {
// Piston
if (state.hasProperty(BlockStateProperties.EXTENDED))
state = state.setValue(BlockStateProperties.EXTENDED, Boolean.FALSE);
if (state.hasProperty(BlockStateProperties.WATERLOGGED))
state = state.setValue(BlockStateProperties.WATERLOGGED, Boolean.FALSE);
if (AllBlocks.BELT.has(state)) {
world.setBlock(target, state, 2);
return;
} else if (state.getBlock() == Blocks.COMPOSTER)
state = Blocks.COMPOSTER.defaultBlockState();
else if (state.getBlock() != Blocks.SEA_PICKLE && state.getBlock() instanceof IPlantable)
state = ((IPlantable) state.getBlock()).getPlant(world, target);
if (world.dimensionType().ultraWarm() && state.getFluidState().getType().is(FluidTags.WATER)) {
int i = target.getX();
int j = target.getY();
int k = target.getZ();
world.playSound(null, target, SoundEvents.FIRE_EXTINGUISH, SoundSource.BLOCKS, 0.5F, 2.6F + (world.random.nextFloat() - world.random.nextFloat()) * 0.8F);
for (int l = 0; l < 8; ++l) {
world.addParticle(ParticleTypes.LARGE_SMOKE, i + Math.random(), j + Math.random(), k + Math.random(), 0.0D, 0.0D, 0.0D);
}
Block.dropResources(state, world, target);
return;
}
if (state.getBlock() instanceof BaseRailBlock) {
placeRailWithoutUpdate(world, state, target);
} else {
world.setBlock(target, state, 18);
}
if (data != null) {
BlockEntity tile = world.getBlockEntity(target);
if (tile != null) {
data.putInt("x", target.getX());
data.putInt("y", target.getY());
data.putInt("z", target.getZ());
if (tile instanceof KineticTileEntity)
((KineticTileEntity) tile).warnOfMovement();
tile.load(data);
}
}
try {
state.getBlock().setPlacedBy(world, target, state, null, stack);
} catch (Exception e) {
}
}
Aggregations