use of me.desht.pneumaticcraft.api.client.pneumaticHelmet.IHackableBlock in project pnc-repressurized by TeamPneumatic.
the class RenderBlockTarget method update.
public void update() {
if (te != null && te.isInvalid())
te = null;
stat.update();
List<IBlockTrackEntry> applicableTrackEntries = getApplicableEntries();
if (CommonHUDHandler.getHandlerForPlayer().ticksExisted % 100 == 0) {
boolean sentUpdate = false;
for (IBlockTrackEntry entry : applicableTrackEntries) {
if (entry.shouldBeUpdatedFromServer(te)) {
if (!sentUpdate) {
NetworkHandler.sendToServer(new PacketDescriptionPacketRequest(pos));
sentUpdate = true;
}
}
}
}
playerIsLooking = isPlayerLookingAtTarget();
arrowRenderer.ticksExisted++;
if (!getBlock().isAir(world.getBlockState(pos), world, pos)) {
textList = new ArrayList<>();
if (ticksExisted > 120) {
stat.closeWindow();
for (IBlockTrackEntry entry : applicableTrackEntries) {
if (blockTracker.countBlockTrackersOfType(entry) <= entry.spamThreshold()) {
stat.openWindow();
break;
}
}
if (playerIsLooking) {
stat.openWindow();
addBlockTrackInfo(textList);
}
stat.setText(textList);
} else if (ticksExisted < -30) {
stat.closeWindow();
stat.setText(textList);
}
}
if (hackTime > 0) {
IHackableBlock hackableBlock = HackableHandler.getHackableForCoord(world, pos, player);
if (hackableBlock != null) {
// = Math.min(hackTime + 1, hackableBlock.getHackTime(world, blockX, blockY, blockZ, player));
hackTime++;
} else {
hackTime = 0;
}
}
}
use of me.desht.pneumaticcraft.api.client.pneumaticHelmet.IHackableBlock in project pnc-repressurized by TeamPneumatic.
the class BlockTrackEntryHackable method addInformation.
@Override
public void addInformation(World world, BlockPos pos, TileEntity te, List<String> infoList) {
IHackableBlock hackableBlock = HackableHandler.getHackableForCoord(world, pos, PneumaticCraftRepressurized.proxy.getPlayer());
int hackTime = HUDHandler.instance().getSpecificRenderer(BlockTrackUpgradeHandler.class).getTargetForCoord(pos).getHackTime();
if (hackTime == 0) {
hackableBlock.addInfo(world, pos, infoList, PneumaticCraftRepressurized.proxy.getPlayer());
} else {
int requiredHackTime = hackableBlock.getHackTime(world, pos, PneumaticCraftRepressurized.proxy.getPlayer());
int percentageComplete = hackTime * 100 / requiredHackTime;
if (percentageComplete < 100) {
infoList.add(I18n.format("pneumaticHelmet.hacking.hacking") + " (" + percentageComplete + "%%)");
} else if (hackTime < requiredHackTime + 20) {
hackableBlock.addPostHackInfo(world, pos, infoList, PneumaticCraftRepressurized.proxy.getPlayer());
} else {
hackableBlock.addInfo(world, pos, infoList, PneumaticCraftRepressurized.proxy.getPlayer());
}
}
}
use of me.desht.pneumaticcraft.api.client.pneumaticHelmet.IHackableBlock in project pnc-repressurized by TeamPneumatic.
the class HackableHandler method getHackableForCoord.
public static IHackableBlock getHackableForCoord(IBlockAccess world, BlockPos pos, EntityPlayer player) {
// clean up the map
Iterator<Map.Entry<WorldAndCoord, IHackableBlock>> iterator = getInstance().trackedHackableBlocks.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<WorldAndCoord, IHackableBlock> entry = iterator.next();
Class<? extends IHackableBlock> hackableBlockClazz = PneumaticHelmetRegistry.getInstance().hackableBlocks.get(entry.getKey().getBlock());
if (hackableBlockClazz != entry.getValue().getClass() || !entry.getValue().canHack(entry.getKey().world, entry.getKey().pos, player) && !isInDisplayCooldown(entry.getValue(), entry.getKey().world, entry.getKey().pos, player))
iterator.remove();
}
Block block = world.getBlockState(pos).getBlock();
if (block instanceof IHackableBlock && ((IHackableBlock) block).canHack(world, pos, player))
return (IHackableBlock) block;
IHackableBlock hackable = getInstance().trackedHackableBlocks.get(new WorldAndCoord(world, pos));
if (hackable == null) {
if (!PneumaticHelmetRegistry.getInstance().hackableBlocks.containsKey(block))
return null;
try {
hackable = PneumaticHelmetRegistry.getInstance().hackableBlocks.get(block).newInstance();
if (hackable.canHack(world, pos, player)) {
getInstance().trackedHackableBlocks.put(new WorldAndCoord(world, pos), hackable);
} else {
hackable = null;
}
} catch (Exception e) {
// shouldn't happen, checked earlier.
e.printStackTrace();
}
}
return hackable;
}
use of me.desht.pneumaticcraft.api.client.pneumaticHelmet.IHackableBlock in project pnc-repressurized by TeamPneumatic.
the class CommonHUDHandler method handleHacking.
private void handleHacking(EntityPlayer player) {
if (hackedBlock != null) {
IHackableBlock hackableBlock = HackableHandler.getHackableForCoord(hackedBlock, player);
if (hackableBlock != null) {
if (++hackTime >= hackableBlock.getHackTime(hackedBlock.world, hackedBlock.pos, player)) {
hackableBlock.onHackFinished(player.world, hackedBlock.pos, player);
PneumaticCraftRepressurized.proxy.getHackTickHandler().trackBlock(hackedBlock, hackableBlock);
NetworkHandler.sendToAllAround(new PacketHackingBlockFinish(hackedBlock), player.world);
setHackedBlock(null);
}
} else {
setHackedBlock(null);
}
} else if (hackedEntity != null) {
IHackableEntity hackableEntity = HackableHandler.getHackableForEntity(hackedEntity, player);
if (hackableEntity != null) {
if (++hackTime >= hackableEntity.getHackTime(hackedEntity, player)) {
hackableEntity.onHackFinished(hackedEntity, player);
PneumaticCraftRepressurized.proxy.getHackTickHandler().trackEntity(hackedEntity, hackableEntity);
NetworkHandler.sendToAllAround(new PacketHackingEntityFinish(hackedEntity), new NetworkRegistry.TargetPoint(hackedEntity.world.provider.getDimension(), hackedEntity.posX, hackedEntity.posY, hackedEntity.posZ, 64));
setHackedEntity(null);
}
} else {
setHackedEntity(null);
}
}
}
use of me.desht.pneumaticcraft.api.client.pneumaticHelmet.IHackableBlock in project pnc-repressurized by TeamPneumatic.
the class HackTickHandler method onServerTick.
@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent event) {
if (event.phase == TickEvent.Phase.END) {
Iterator<Map.Entry<WorldAndCoord, IHackableBlock>> blockIterator = hackedBlocks.entrySet().iterator();
while (blockIterator.hasNext()) {
Map.Entry<WorldAndCoord, IHackableBlock> entry = blockIterator.next();
IHackableBlock hackableBlock = entry.getValue();
WorldAndCoord hackedBlock = entry.getKey();
boolean found = false;
for (Map.Entry<Block, Class<? extends IHackableBlock>> registeredEntry : PneumaticHelmetRegistry.getInstance().hackableBlocks.entrySet()) {
if (hackableBlock.getClass() == registeredEntry.getValue()) {
if (hackedBlock.getBlock() == registeredEntry.getKey()) {
if (!hackableBlock.afterHackTick((World) hackedBlock.world, hackedBlock.pos)) {
blockIterator.remove();
}
found = true;
break;
}
}
}
if (!found)
blockIterator.remove();
}
}
}
Aggregations