use of me.desht.pneumaticcraft.common.util.WorldAndCoord 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.common.util.WorldAndCoord 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();
}
}
}
use of me.desht.pneumaticcraft.common.util.WorldAndCoord in project pnc-repressurized by TeamPneumatic.
the class PacketHackingBlockStart method handleClientSide.
@Override
public void handleClientSide(PacketHackingBlockStart message, EntityPlayer player) {
CommonHUDHandler.getHandlerForPlayer(player).setHackedBlock(new WorldAndCoord(player.world, message.pos));
RenderBlockTarget target = HUDHandler.instance().getSpecificRenderer(BlockTrackUpgradeHandler.class).getTargetForCoord(message.pos);
if (target != null)
target.onHackConfirmServer();
}
use of me.desht.pneumaticcraft.common.util.WorldAndCoord in project pnc-repressurized by TeamPneumatic.
the class PacketHackingBlockFinish method handleClientSide.
@Override
public void handleClientSide(PacketHackingBlockFinish message, EntityPlayer player) {
IHackableBlock hackableBlock = HackableHandler.getHackableForCoord(player.world, message.pos, player);
if (hackableBlock != null) {
hackableBlock.onHackFinished(player.world, message.pos, player);
PneumaticCraftRepressurized.proxy.getHackTickHandler().trackBlock(new WorldAndCoord(player.world, message.pos), hackableBlock);
CommonHUDHandler.getHandlerForPlayer(player).setHackedBlock(null);
player.playSound(Sounds.HELMET_HACK_FINISH, 1.0F, 1.0F);
}
}
use of me.desht.pneumaticcraft.common.util.WorldAndCoord in project pnc-repressurized by TeamPneumatic.
the class PacketHackingBlockStart method handleServerSide.
@Override
public void handleServerSide(PacketHackingBlockStart message, EntityPlayer player) {
CommonHUDHandler.getHandlerForPlayer(player).setHackedBlock(new WorldAndCoord(player.world, message.pos));
NetworkHandler.sendToAllAround(message, player.world);
}
Aggregations