use of com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity in project Enchanted by Favouriteless.
the class AbstractRite method detatchFromChalk.
protected void detatchFromChalk() {
TileEntity te = world.getBlockEntity(pos);
if (te instanceof ChalkGoldTileEntity) {
ChalkGoldTileEntity chalk = (ChalkGoldTileEntity) te;
if (chalk.getRite() == this)
chalk.clearRite();
}
isAttached = false;
}
use of com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity in project Enchanted by Favouriteless.
the class AbstractRite method cancel.
public void cancel() {
isStarting = false;
RiteManager.removeRite(this);
while (!itemsConsumed.isEmpty()) {
ItemStack stack = itemsConsumed.get(0);
ItemEntity entity = new ItemEntity(world, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, stack);
world.addFreshEntity(entity);
itemsConsumed.remove(stack);
}
world.playSound(null, pos, SoundEvents.NOTE_BLOCK_SNARE, SoundCategory.MASTER, 1.0F, 1.0F);
PlayerEntity player = world.getPlayerByUUID(casterUUID);
if (player != null)
player.displayClientMessage(new StringTextComponent("Rite failed.").withStyle(TextFormatting.RED), false);
for (int i = 0; i < 25; i++) {
double dx = pos.getX() + Math.random();
double dy = pos.getY() + Math.random();
double dz = pos.getZ() + Math.random();
world.sendParticles(new RedstoneParticleData(254 / 255F, 94 / 255F, 94 / 255F, 1.0F), dx, dy, dz, 1, 0.0F, 0.0F, 0.0F, 0.0F);
}
TileEntity te = world.getBlockEntity(pos);
if (te instanceof ChalkGoldTileEntity) {
((ChalkGoldTileEntity) te).clearRite();
}
}
use of com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity in project Enchanted by Favouriteless.
the class AbstractRite method stopExecuting.
/**
* Call this when the rite is finished
*/
public void stopExecuting() {
detatchFromChalk();
this.isStarting = false;
TileEntity te = world.getBlockEntity(pos);
if (te instanceof ChalkGoldTileEntity) {
((ChalkGoldTileEntity) te).clearRite();
}
RiteManager.removeRite(this);
}
use of com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity in project Enchanted by Favouriteless.
the class AbstractRite method tryConsumePower.
protected boolean tryConsumePower(int amount) {
if (world != null) {
if (amount > 0) {
TileEntity te = world.getBlockEntity(pos);
if (te instanceof ChalkGoldTileEntity) {
List<BlockPos> potentialAltars = ((ChalkGoldTileEntity) te).getAltarPositions();
AltarTileEntity altar = AltarPowerHelper.tryGetAltar(world, potentialAltars);
if (altar != null) {
if (altar.currentPower >= amount) {
altar.currentPower -= amount;
return true;
}
}
}
} else {
return true;
}
}
return false;
}
use of com.favouriteless.enchanted.common.tileentity.ChalkGoldTileEntity in project Enchanted by Favouriteless.
the class AbstractRite method tick.
public void tick() {
if (world != null && !world.isClientSide) {
if (isAttached && chalk == null) {
TileEntity te = world.getBlockEntity(pos);
if (te instanceof ChalkGoldTileEntity) {
setChalk((ChalkGoldTileEntity) te);
chalk.setRite(this);
}
}
ticks++;
if (isStarting) {
if (ticks % 20 == 0) {
List<Entity> allEntities = world.getEntities(null, new AxisAlignedBB(pos.offset(-7, 0, -7), pos.offset(7, 1, 7)));
boolean hasItem = false;
for (Entity entity : allEntities) {
if (entity instanceof ItemEntity) {
ItemEntity itemEntity = (ItemEntity) entity;
if (ITEMS_REQUIRED.containsKey(itemEntity.getItem().getItem())) {
consumeItem(itemEntity);
hasItem = true;
break;
}
}
}
boolean hasEntity = false;
if (!hasItem) {
if (ITEMS_REQUIRED.isEmpty()) {
for (Entity entity : allEntities) {
if (ENTITIES_REQUIRED.containsKey(entity.getType())) {
hasEntity = true;
consumeEntity(entity);
break;
}
}
} else {
cancel();
return;
}
if (!hasEntity) {
if (ENTITIES_REQUIRED.isEmpty()) {
startExecuting();
} else {
cancel();
}
}
}
}
} else if (!isRemoved) {
if (tryConsumePower(POWER_TICK))
onTick();
else
stopExecuting();
}
}
}
Aggregations