use of micdoodle8.mods.galacticraft.api.item.IKeyable in project Galacticraft by micdoodle8.
the class EventHandlerGC method onPlayerClicked.
@SubscribeEvent
public void onPlayerClicked(PlayerInteractEvent event) {
// Skip events triggered from Thaumcraft Golems and other non-players
if (event.entityPlayer == null || event.entityPlayer.inventory == null || event.pos == null || (event.pos.getX() == 0 && event.pos.getY() == 0 && event.pos.getZ() == 0)) {
return;
}
final World worldObj = event.entityPlayer.worldObj;
if (worldObj == null) {
return;
}
final Block idClicked = worldObj.getBlockState(event.pos).getBlock();
if (idClicked == Blocks.bed && worldObj.provider instanceof IGalacticraftWorldProvider && event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) && !worldObj.isRemote && !((IGalacticraftWorldProvider) worldObj.provider).hasBreathableAtmosphere()) {
if (GalacticraftCore.isPlanetsLoaded) {
GCPlayerStats stats = GCPlayerStats.get(event.entityPlayer);
if (!stats.hasReceivedBedWarning()) {
event.entityPlayer.addChatMessage(new ChatComponentText(GCCoreUtil.translate("gui.bed_fail.message")));
stats.setReceivedBedWarning(true);
}
}
if (worldObj.provider instanceof WorldProviderSpaceStation) {
// On space stations simply block the bed activation => no explosion
event.setCanceled(true);
return;
}
// Optionally prevent beds from exploding - depends on canRespawnHere() in the WorldProvider interacting with this
EventHandlerGC.bedActivated = true;
if (worldObj.provider.canRespawnHere() && !EventHandlerGC.bedActivated) {
EventHandlerGC.bedActivated = true;
// On planets allow the bed to be used to designate a player spawn point
event.entityPlayer.setSpawnChunk(event.pos, false, GCCoreUtil.getDimensionID(event.world));
} else {
EventHandlerGC.bedActivated = false;
}
}
final ItemStack heldStack = event.entityPlayer.inventory.getCurrentItem();
final TileEntity tileClicked = worldObj.getTileEntity(event.pos);
if (heldStack != null) {
if (tileClicked != null && tileClicked instanceof IKeyable) {
if (event.action.equals(PlayerInteractEvent.Action.LEFT_CLICK_BLOCK)) {
event.setCanceled(!((IKeyable) tileClicked).canBreak() && !event.entityPlayer.capabilities.isCreativeMode);
return;
} else if (event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)) {
if (heldStack.getItem() instanceof IKeyItem) {
if (((IKeyItem) heldStack.getItem()).getTier(heldStack) == -1 || ((IKeyable) tileClicked).getTierOfKeyRequired() == -1 || ((IKeyItem) heldStack.getItem()).getTier(heldStack) == ((IKeyable) tileClicked).getTierOfKeyRequired()) {
event.setCanceled(((IKeyable) tileClicked).onValidKeyActivated(event.entityPlayer, heldStack, event.face));
} else {
event.setCanceled(((IKeyable) tileClicked).onActivatedWithoutKey(event.entityPlayer, event.face));
}
} else if (!event.entityPlayer.isSneaking()) {
event.setCanceled(((IKeyable) tileClicked).onActivatedWithoutKey(event.entityPlayer, event.face));
}
}
}
if (heldStack.getItem() instanceof ItemFlintAndSteel || heldStack.getItem() instanceof ItemFireball) {
if (!worldObj.isRemote && event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)) {
if (idClicked != Blocks.tnt && OxygenUtil.noAtmosphericCombustion(event.entityPlayer.worldObj.provider) && !OxygenUtil.isAABBInBreathableAirBlock(event.entityLiving.worldObj, AxisAlignedBB.fromBounds(event.pos.getX(), event.pos.getY(), event.pos.getZ(), event.pos.getX() + 1, event.pos.getY() + 2, event.pos.getZ() + 1))) {
event.setCanceled(true);
}
}
}
} else if (tileClicked != null && tileClicked instanceof IKeyable) {
if (event.action.equals(PlayerInteractEvent.Action.LEFT_CLICK_BLOCK)) {
event.setCanceled(!((IKeyable) tileClicked).canBreak() && !event.entityPlayer.capabilities.isCreativeMode);
return;
}
event.setCanceled(((IKeyable) tileClicked).onActivatedWithoutKey(event.entityPlayer, event.face));
}
}
Aggregations