use of com.fredtargaryen.fragileglass.config.behaviour.data.FragilityData in project Fragile-Glass by fredtargaryen.
the class BreakSystem method updateBehaviourQueue.
/**
* Process a BehaviourQueue in this.queuedBehaviours. If the queue is waiting decrease the amount of time it has to
* wait. If it is no longer waiting execute all crash behaviours up to the next wait behaviour or the end of the
* queue.
* @param pos The position at which the queue of behaviours is executing
* @param bq The behaviours being executed.
* @return True if the queue should continue executing; false if the end of the queue has been reached.
*/
private boolean updateBehaviourQueue(BlockPos pos, BehaviourQueue bq) {
if (bq.countdown == 0) {
ArrayList<FragilityData> fragDataList;
if (bq.tileEntityType == null) {
fragDataList = this.blockDataManager.getData(bq.state);
} else {
fragDataList = this.tileEntityDataManager.getData(bq.tileEntityType);
}
if (fragDataList != null && bq.nextBehaviourIndex < fragDataList.size()) {
// Execute all behaviours up to the end or the next WAIT
int i = bq.nextBehaviourIndex;
boolean stop = false;
while (!stop && i < fragDataList.size()) {
FragilityData fd = fragDataList.get(i);
if (fd.getBehaviour() == FragilityData.FragileBehaviour.WAIT) {
if (bq.speedSq > fd.getBreakSpeedSq()) {
bq.countdown = ((WaitData) fd).getTicks();
bq.nextBehaviourIndex = i + 1;
stop = true;
}
} else if (fd.canBeQueued()) {
fd.onCrash(this.world, bq.state, null, pos, null, bq.speedSq);
}
i++;
}
this.markDirty();
if (i == fragDataList.size())
return false;
} else {
return false;
}
} else {
bq.countdown--;
this.markDirty();
}
return true;
}
use of com.fredtargaryen.fragileglass.config.behaviour.data.FragilityData in project Fragile-Glass by fredtargaryen.
the class BreakSystem method breakNearbyFragileBlocks.
/**
* @param e The entity doing the breaking
* @param aabb The bounding box to break blocks around
* @param speedSq The square of the speed e is travelling at
*/
private void breakNearbyFragileBlocks(Entity e, AxisAlignedBB aabb, double speedSq) {
BlockPos blockPos;
Block block;
for (double x = Math.floor(aabb.minX); x < Math.ceil(aabb.maxX); ++x) {
for (double y = Math.floor(aabb.minY); y < Math.ceil(aabb.maxY); ++y) {
for (double z = Math.floor(aabb.minZ); z < Math.ceil(aabb.maxZ); ++z) {
blockPos = new BlockPos(x, y, z);
BlockState state = e.world.getBlockState(blockPos);
block = state.getBlock();
// Chances are the block will be an air block (pass through no question) so best check this first
if (!block.isAir(state, e.world, blockPos)) {
TileEntity te = e.world.getTileEntity(blockPos);
if (te == null) {
// No Tile Entity. The specific BlockState might be covered in the fragility data
ArrayList<FragilityData> fragilityDataList = this.blockDataManager.getData(state);
if (fragilityDataList != null) {
this.initialUpdateFragilityDataList(state, null, blockPos, e, speedSq, fragilityDataList);
}
} else {
// Has a Tile Entity; call all FragilityDatas. Mod FragilityDatas call onCrash in
// the TileEntity's capability.
ArrayList<FragilityData> fragilityDataList = this.tileEntityDataManager.getData(te.getType());
if (fragilityDataList != null) {
this.initialUpdateFragilityDataList(state, te, blockPos, e, speedSq, fragilityDataList);
}
}
}
}
}
}
}
use of com.fredtargaryen.fragileglass.config.behaviour.data.FragilityData in project Fragile-Glass by fredtargaryen.
the class BreakSystem method initialUpdateFragilityDataList.
/**
* Go through all behaviours associated with the BlockState state or TileEntity te.
* Execute all behaviours until a WAIT behaviour is encountered; at which point put a BehaviourQueue in
* queuedBehaviours.
* @param state
* @param te
* @param pos
* @param e
* @param speedSq
* @param fragDataList
*/
private void initialUpdateFragilityDataList(BlockState state, @Nullable TileEntity te, BlockPos pos, Entity e, double speedSq, ArrayList<FragilityData> fragDataList) {
int i = 0;
int listSize = fragDataList.size();
boolean stop = false;
while (!stop && i < listSize) {
FragilityData fData = fragDataList.get(i);
if (fData.getBehaviour() == FragilityData.FragileBehaviour.WAIT) {
if (!this.queuedBehaviours.containsKey(pos)) {
if (speedSq >= fData.getBreakSpeedSq()) {
this.queuedBehaviours.put(pos, new BehaviourQueue(((WaitData) fData).getTicks(), state, te == null ? null : te.getType(), speedSq, i + 1));
}
stop = true;
}
} else {
fData.onCrash(this.world, state, te, pos, e, speedSq);
}
i++;
}
}
use of com.fredtargaryen.fragileglass.config.behaviour.data.FragilityData in project Fragile-Glass by fredtargaryen.
the class BlockDataManager method stringifyBehaviours.
@Override
public String stringifyBehaviours(BlockState key, @Nullable FragilityData.FragileBehaviour behaviour, boolean showNumbers) {
StringBuilder sb = new StringBuilder();
List<FragilityData> list = this.data.get(key);
for (int i = 0; i < list.size(); i++) {
FragilityData fd = list.get(i);
if (behaviour == null || behaviour == fd.getBehaviour()) {
if (showNumbers) {
sb.append('[');
sb.append(i);
sb.append("] ");
}
sb.append(KeyParser.cleanBlockStateString(key.toString()));
sb.append(" ");
sb.append(fd.toString());
sb.append("\n");
}
}
return sb.toString();
}
use of com.fredtargaryen.fragileglass.config.behaviour.data.FragilityData in project Fragile-Glass by fredtargaryen.
the class TileEntityDataManager method stringifyBehaviours.
@Override
public String stringifyBehaviours(TileEntityType key, @Nullable FragilityData.FragileBehaviour behaviour, boolean showNumbers) {
StringBuilder sb = new StringBuilder();
List<FragilityData> list = this.data.get(key);
for (int i = 0; i < list.size(); i++) {
FragilityData fd = list.get(i);
if (behaviour == null || behaviour == fd.getBehaviour()) {
if (showNumbers) {
sb.append('[');
sb.append(i);
sb.append("] ");
}
sb.append(key.getRegistryName());
sb.append(" ");
sb.append(fd.toString());
sb.append("\n");
}
}
return sb.toString();
}
Aggregations