Search in sources :

Example 1 with ItemFlintAndSteel

use of net.minecraft.item.ItemFlintAndSteel 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));
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ItemFireball(net.minecraft.item.ItemFireball) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) IKeyItem(micdoodle8.mods.galacticraft.api.item.IKeyItem) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) ItemFlintAndSteel(net.minecraft.item.ItemFlintAndSteel) Block(net.minecraft.block.Block) IKeyable(micdoodle8.mods.galacticraft.api.item.IKeyable) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

IKeyItem (micdoodle8.mods.galacticraft.api.item.IKeyItem)1 IKeyable (micdoodle8.mods.galacticraft.api.item.IKeyable)1 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)1 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)1 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)1 Block (net.minecraft.block.Block)1 ItemFireball (net.minecraft.item.ItemFireball)1 ItemFlintAndSteel (net.minecraft.item.ItemFlintAndSteel)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1