use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create by Creators-of-Create.
the class KineticNetwork method calculateStress.
public float calculateStress() {
float presentStress = 0;
for (Iterator<KineticTileEntity> iterator = members.keySet().iterator(); iterator.hasNext(); ) {
KineticTileEntity te = iterator.next();
if (te.getLevel().getBlockEntity(te.getBlockPos()) != te) {
iterator.remove();
continue;
}
presentStress += getActualStressOf(te);
}
float newStress = presentStress + unloadedStress;
return newStress;
}
use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create by Creators-of-Create.
the class KineticNetwork method calculateCapacity.
public float calculateCapacity() {
float presentCapacity = 0;
containsFlywheel = false;
for (Iterator<KineticTileEntity> iterator = sources.keySet().iterator(); iterator.hasNext(); ) {
KineticTileEntity te = iterator.next();
if (te.getLevel().getBlockEntity(te.getBlockPos()) != te) {
iterator.remove();
continue;
}
containsFlywheel |= te instanceof FlywheelTileEntity;
presentCapacity += getActualCapacityOf(te);
}
float newMaxStress = presentCapacity + unloadedCapacity;
return newMaxStress;
}
use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create by Creators-of-Create.
the class RotationPropagator method findConnectedNeighbour.
private static KineticTileEntity findConnectedNeighbour(KineticTileEntity currentTE, BlockPos neighbourPos) {
BlockState neighbourState = currentTE.getLevel().getBlockState(neighbourPos);
if (!(neighbourState.getBlock() instanceof IRotate))
return null;
if (!neighbourState.hasBlockEntity())
return null;
BlockEntity neighbourTE = currentTE.getLevel().getBlockEntity(neighbourPos);
if (!(neighbourTE instanceof KineticTileEntity))
return null;
KineticTileEntity neighbourKTE = (KineticTileEntity) neighbourTE;
if (!(neighbourKTE.getBlockState().getBlock() instanceof IRotate))
return null;
if (!isConnected(currentTE, neighbourKTE) && !isConnected(neighbourKTE, currentTE))
return null;
return neighbourKTE;
}
use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create by Creators-of-Create.
the class RotationPropagator method propagateNewSource.
/**
* Search for sourceless networks attached to the given entity and update them.
*
* @param currentTE
*/
private static void propagateNewSource(KineticTileEntity currentTE) {
BlockPos pos = currentTE.getBlockPos();
Level world = currentTE.getLevel();
for (KineticTileEntity neighbourTE : getConnectedNeighbours(currentTE)) {
float speedOfCurrent = currentTE.getTheoreticalSpeed();
float speedOfNeighbour = neighbourTE.getTheoreticalSpeed();
float newSpeed = getConveyedSpeed(currentTE, neighbourTE);
float oppositeSpeed = getConveyedSpeed(neighbourTE, currentTE);
if (newSpeed == 0 && oppositeSpeed == 0)
continue;
boolean incompatible = Math.signum(newSpeed) != Math.signum(speedOfNeighbour) && (newSpeed != 0 && speedOfNeighbour != 0);
boolean tooFast = Math.abs(newSpeed) > AllConfigs.SERVER.kinetics.maxRotationSpeed.get();
boolean speedChangedTooOften = currentTE.getFlickerScore() > MAX_FLICKER_SCORE;
if (tooFast || speedChangedTooOften) {
world.destroyBlock(pos, true);
return;
}
// Opposite directions
if (incompatible) {
world.destroyBlock(pos, true);
return;
// Same direction: overpower the slower speed
} else {
// Neighbour faster, overpower the incoming tree
if (Math.abs(oppositeSpeed) > Math.abs(speedOfCurrent)) {
float prevSpeed = currentTE.getSpeed();
currentTE.setSource(neighbourTE.getBlockPos());
currentTE.setSpeed(getConveyedSpeed(neighbourTE, currentTE));
currentTE.onSpeedChanged(prevSpeed);
currentTE.sendData();
propagateNewSource(currentTE);
return;
}
// Current faster, overpower the neighbours' tree
if (Math.abs(newSpeed) >= Math.abs(speedOfNeighbour)) {
// Do not overpower you own network -> cycle
if (!currentTE.hasNetwork() || currentTE.network.equals(neighbourTE.network)) {
float epsilon = Math.abs(speedOfNeighbour) / 256f / 256f;
if (Math.abs(newSpeed) > Math.abs(speedOfNeighbour) + epsilon)
world.destroyBlock(pos, true);
continue;
}
if (currentTE.hasSource() && currentTE.source.equals(neighbourTE.getBlockPos()))
currentTE.removeSource();
float prevSpeed = neighbourTE.getSpeed();
neighbourTE.setSource(currentTE.getBlockPos());
neighbourTE.setSpeed(getConveyedSpeed(currentTE, neighbourTE));
neighbourTE.onSpeedChanged(prevSpeed);
neighbourTE.sendData();
propagateNewSource(neighbourTE);
continue;
}
}
if (neighbourTE.getTheoreticalSpeed() == newSpeed)
continue;
float 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 Multiblocked by Low-Drag-MC.
the class CreateKineticSourceTileEntity method setSource.
public void setSource(BlockPos source) {
super.setSource(source);
if (!definition.isOutput)
return;
TileEntity tileEntity = this.level.getBlockEntity(source);
if (tileEntity instanceof KineticTileEntity) {
KineticTileEntity sourceTe = (KineticTileEntity) tileEntity;
if (this.reActivateSource && Math.abs(sourceTe.getSpeed()) >= Math.abs(this.getGeneratedSpeed())) {
this.reActivateSource = false;
}
}
}
Aggregations