use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create_Aeronautics by Eriksonnaren.
the class TorsionSpringTileEntity method tick.
public void tick(BlockState state, ServerWorld worldIn, BlockPos pos, Random random) {
TileEntity te = worldIn.getBlockEntity(pos);
if (te != null && te instanceof KineticTileEntity) {
externalChange = false;
KineticTileEntity kte = (KineticTileEntity) te;
RotationPropagator.handleAdded(worldIn, pos, kte);
}
}
use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create_Aeronautics by Eriksonnaren.
the class TorsionSpringTileEntity method detachKinetics.
public void detachKinetics(World worldIn, BlockPos pos, boolean reAttachNextTick) {
TileEntity te = worldIn.getBlockEntity(pos);
if (te != null && te instanceof KineticTileEntity) {
RotationPropagator.handleRemoved(worldIn, pos, (KineticTileEntity) te);
if (reAttachNextTick) {
externalChange = false;
worldIn.getBlockTicks().scheduleTick(pos, getBlockState().getBlock(), 0, TickPriority.EXTREMELY_HIGH);
}
}
}
use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create_Aeronautics by Eriksonnaren.
the class RotationPropagatorMixin method propagateNewSource.
/**
* @author Eriksonn
* @reason Allows generator blocks to have different rotation speeds on different output sides
*/
@Overwrite(remap = false)
private static void propagateNewSource(KineticTileEntity currentTE) {
BlockPos pos = currentTE.getBlockPos();
World world = currentTE.getLevel();
Iterator var3 = getConnectedNeighbours(currentTE).iterator();
while (true) {
KineticTileEntity neighbourTE;
float speedOfCurrent;
float speedOfNeighbour;
float newSpeed;
float oppositeSpeed;
do {
if (!var3.hasNext()) {
return;
}
neighbourTE = (KineticTileEntity) var3.next();
speedOfCurrent = currentTE.getTheoreticalSpeed();
speedOfNeighbour = neighbourTE.getTheoreticalSpeed();
newSpeed = getConveyedSpeed(currentTE, neighbourTE);
oppositeSpeed = getConveyedSpeed(neighbourTE, currentTE);
} while (newSpeed == 0.0F && oppositeSpeed == 0.0F);
boolean incompatible = Math.signum(newSpeed) != Math.signum(speedOfNeighbour) && newSpeed != 0.0F && speedOfNeighbour != 0.0F;
boolean tooFast = Math.abs(newSpeed) > (float) (Integer) AllConfigs.SERVER.kinetics.maxRotationSpeed.get();
boolean speedChangedTooOften = currentTE.getFlickerScore() > 128;
if (tooFast || speedChangedTooOften) {
world.destroyBlock(pos, true);
return;
}
if (incompatible) {
world.destroyBlock(pos, true);
return;
}
float prevSpeed;
if (Math.abs(oppositeSpeed) > Math.abs(speedOfCurrent)) {
prevSpeed = currentTE.getSpeed();
currentTE.setSource(neighbourTE.getBlockPos());
currentTE.setSpeed(getConveyedSpeed(neighbourTE, currentTE));
currentTE.onSpeedChanged(prevSpeed);
currentTE.sendData();
propagateNewSource(currentTE);
return;
}
if (Math.abs(newSpeed) >= Math.abs(speedOfNeighbour)) {
if (currentTE.hasNetwork() && !currentTE.network.equals(neighbourTE.network)) {
if (currentTE.hasSource() && currentTE.source.equals(neighbourTE.getBlockPos())) {
currentTE.removeSource();
}
prevSpeed = neighbourTE.getSpeed();
neighbourTE.setSource(currentTE.getBlockPos());
neighbourTE.setSpeed(getConveyedSpeed(currentTE, neighbourTE));
neighbourTE.onSpeedChanged(prevSpeed);
neighbourTE.sendData();
propagateNewSource(neighbourTE);
} else {
prevSpeed = Math.abs(speedOfNeighbour) / 256.0F / 256.0F;
if (Math.abs(newSpeed) > Math.abs(speedOfNeighbour) + prevSpeed) {
world.destroyBlock(pos, true);
}
}
} else if (neighbourTE.getTheoreticalSpeed() != newSpeed) {
prevSpeed = neighbourTE.getSpeed();
neighbourTE.setSpeed(newSpeed);
neighbourTE.setSource(currentTE.getBlockPos());
neighbourTE.onSpeedChanged(prevSpeed);
neighbourTE.sendData();
propagateNewSource(neighbourTE);
}
}
}
use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create_Aeronautics by Eriksonnaren.
the class RotationPropagatorMixin method getConnectedNeighbours.
private static List<KineticTileEntity> getConnectedNeighbours(KineticTileEntity te) {
List<KineticTileEntity> neighbours = new LinkedList();
Iterator var2 = getPotentialNeighbourLocations(te).iterator();
while (var2.hasNext()) {
BlockPos neighbourPos = (BlockPos) var2.next();
KineticTileEntity neighbourTE = findConnectedNeighbour(te, neighbourPos);
if (neighbourTE != null) {
neighbours.add(neighbourTE);
}
}
return neighbours;
}
use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create by Creators-of-Create.
the class Contraption method readBlocksCompound.
private void readBlocksCompound(Tag compound, Level world, boolean usePalettedDeserialization) {
HashMapPalette<BlockState> palette = null;
ListTag blockList;
if (usePalettedDeserialization) {
CompoundTag c = ((CompoundTag) compound);
palette = new HashMapPalette<>(GameData.getBlockStateIDMap(), 16, (i, s) -> {
throw new IllegalStateException("Palette Map index exceeded maximum");
});
ListTag list = c.getList("Palette", 10);
palette.values.clear();
for (int i = 0; i < list.size(); ++i) palette.values.add(NbtUtils.readBlockState(list.getCompound(i)));
blockList = c.getList("BlockList", 10);
} else {
blockList = (ListTag) compound;
}
HashMapPalette<BlockState> finalPalette = palette;
blockList.forEach(e -> {
CompoundTag c = (CompoundTag) e;
StructureBlockInfo info = usePalettedDeserialization ? readStructureBlockInfo(c, finalPalette) : legacyReadStructureBlockInfo(c);
this.blocks.put(info.pos, info);
if (world.isClientSide) {
Block block = info.state.getBlock();
CompoundTag tag = info.nbt;
MovementBehaviour movementBehaviour = AllMovementBehaviours.of(block);
if (tag == null)
return;
tag.putInt("x", info.pos.getX());
tag.putInt("y", info.pos.getY());
tag.putInt("z", info.pos.getZ());
BlockEntity te = BlockEntity.loadStatic(info.pos, info.state, tag);
if (te == null)
return;
te.setLevel(world);
if (te instanceof KineticTileEntity)
((KineticTileEntity) te).setSpeed(0);
te.getBlockState();
if (movementBehaviour == null || !movementBehaviour.hasSpecialInstancedRendering())
maybeInstancedTileEntities.add(te);
if (movementBehaviour != null && !movementBehaviour.renderAsNormalTileEntity())
return;
presentTileEntities.put(info.pos, te);
specialRenderedTileEntities.add(te);
}
});
}
Aggregations