Search in sources :

Example 1 with ItemDoor

use of net.minecraft.item.ItemDoor in project Tropicraft by Tropicraft.

the class ItemRegistry method registerItems.

@SubscribeEvent
public static void registerItems(RegistryEvent.Register<Item> event) {
    blockItemRegistry.entrySet().forEach(e -> {
        Item item = e.getValue().getItem(e.getKey());
        item.setRegistryName(e.getKey().getRegistryName());
        event.getRegistry().register(item);
        e.getValue().postRegister(e.getKey(), item);
    });
    IForgeRegistry<Item> registry = event.getRegistry();
    diveComputer = registerItem(registry, new ItemDiveComputer(), "dive_computer");
    pinkWeightBelt = registerItem(registry, new ItemTropicraft(), "pink_weight_belt");
    pinkPonyBottle = registerItem(registry, new ItemPonyBottle(), "pink_pony_bottle");
    pinkBCD = registerItem(registry, new ItemBCD(), "pink_bcd");
    pinkRegulator = registerItem(registry, new ItemTropicraft(), "pink_regulator");
    pinkScubaTank = registerItem(registry, new ItemScubaTank(), "pink_scuba_tank");
    pinkFlippers = registerItem(registry, new ItemScubaFlippers(materialPinkSuit, ScubaMaterial.PINK, 0, EntityEquipmentSlot.FEET), "pink_flippers");
    pinkChestplateGear = registerItem(registry, new ItemScubaChestplateGear(materialPinkSuit, ScubaMaterial.PINK, 0, EntityEquipmentSlot.CHEST), "pink_chestplate_gear");
    pinkScubaGoggles = registerItem(registry, new ItemScubaHelmet(materialPinkSuit, ScubaMaterial.PINK, 0, EntityEquipmentSlot.HEAD), "pink_scuba_goggles");
    yellowWeightBelt = registerItem(registry, new ItemTropicraft(), "yellow_weight_belt");
    yellowPonyBottle = registerItem(registry, new ItemPonyBottle(), "yellow_pony_bottle");
    yellowBCD = registerItem(registry, new ItemBCD(), "yellow_bcd");
    yellowRegulator = registerItem(registry, new ItemTropicraft(), "yellow_regulator");
    yellowScubaTank = registerItem(registry, new ItemScubaTank(), "yellow_scuba_tank");
    yellowFlippers = registerItem(registry, new ItemScubaFlippers(materialYellowSuit, ScubaMaterial.YELLOW, 0, EntityEquipmentSlot.FEET), "yellow_flippers");
    yellowChestplateGear = registerItem(registry, new ItemScubaChestplateGear(materialYellowSuit, ScubaMaterial.YELLOW, 0, EntityEquipmentSlot.CHEST), "yellow_chestplate_gear");
    yellowScubaGoggles = registerItem(registry, new ItemScubaHelmet(materialYellowSuit, ScubaMaterial.YELLOW, 0, EntityEquipmentSlot.HEAD), "yellow_scuba_goggles");
    recordBuriedTreasure = registerItem(registry, new ItemMusicDisc("buried_treasure", "Punchaface", TropicraftSounds.BURIED_TREASURE), "buried_treasure");
    recordEasternIsles = registerItem(registry, new ItemMusicDisc("eastern_isles", "Frox", TropicraftSounds.EASTERN_ISLES), "eastern_isles");
    recordSummering = registerItem(registry, new ItemMusicDisc("summering", "Billy Christiansen", TropicraftSounds.SUMMERING), "summering");
    recordTheTribe = registerItem(registry, new ItemMusicDisc("the_tribe", "Emile Van Krieken", TropicraftSounds.THE_TRIBE), "the_tribe");
    recordLowTide = registerItem(registry, new ItemMusicDisc("low_tide", "Punchaface", TropicraftSounds.LOW_TIDE), "low_tide");
    recordTradeWinds = registerItem(registry, new ItemMusicDisc("trade_winds", "Frox", TropicraftSounds.TRADE_WINDS), "trade_winds");
    azurite = registerItem(registry, new ItemTropicsOre(), "azurite");
    OreDictionary.registerOre("gemAzurite", azurite);
    eudialyte = registerItem(registry, new ItemTropicsOre(), "eudialyte");
    OreDictionary.registerOre("gemEudialyte", eudialyte);
    zircon = registerItem(registry, new ItemTropicsOre(), "zircon");
    OreDictionary.registerOre("gemZircon", zircon);
    grapefruit = registerItem(registry, new ItemTropicraftFood(2, 0.2F), "grapefruit");
    lemon = registerItem(registry, new ItemTropicraftFood(2, 0.2F), "lemon");
    lime = registerItem(registry, new ItemTropicraftFood(2, 0.2F), "lime");
    orange = registerItem(registry, new ItemTropicraftFood(2, 0.2F), "orange");
    hoeEudialyte = registerItem(registry, new ItemHoe(materialEudialyteTools), "hoe_eudialyte");
    hoeZircon = registerItem(registry, new ItemHoe(materialZirconTools), "hoe_zircon");
    pickaxeEudialyte = registerItem(registry, new ItemTropicraftPickaxe(materialEudialyteTools), "pickaxe_eudialyte");
    pickaxeZircon = registerItem(registry, new ItemTropicraftPickaxe(materialZirconTools), "pickaxe_zircon");
    shovelEudialyte = registerItem(registry, new ItemSpade(materialEudialyteTools), "shovel_eudialyte");
    shovelZircon = registerItem(registry, new ItemSpade(materialZirconTools), "shovel_zircon");
    axeEudialyte = registerItem(registry, new ItemTropicraftAxe(materialEudialyteTools, 6.0F, -3.1F), "axe_eudialyte");
    axeZircon = registerItem(registry, new ItemTropicraftAxe(materialZirconTools, 6.0F, -3.2F), "axe_zircon");
    swordEudialyte = registerItem(registry, new ItemSword(materialEudialyteTools), "sword_eudialyte");
    swordZircon = registerItem(registry, new ItemSword(materialZirconTools), "sword_zircon");
    fishingNet = registerItem(registry, new ItemTropicraft(), "fishing_net");
    bambooStick = registerItem(registry, new ItemTropicraft(), "bamboo_stick");
    // Note: Commented out because bamboo ladder recipe would make wooden ladders
    // OreDictionary.registerOre("stickWood", bambooStick);
    bambooMug = registerItem(registry, new ItemTropicraft().setMaxStackSize(16), "bamboo_mug");
    freshMarlin = registerItem(registry, new ItemTropicraftFood(2, 0.3F), "fresh_marlin");
    searedMarlin = registerItem(registry, new ItemTropicraftFood(8, 0.65F), "seared_marlin");
    tropicsWaterBucket = registerItem(registry, (new ItemBucket(BlockRegistry.tropicsWater)).setContainerItem(Items.BUCKET), "tropics_water_bucket");
    fishBucket = registerItem(registry, new ItemFishBucket(), "fish_bucket");
    coconutChunk = registerItem(registry, new ItemTropicraftFood(1, 0.1F), "coconut_chunk");
    pineappleCubes = registerItem(registry, new ItemTropicraftFood(1, 0.1F), "pineapple_cubes");
    coffeeBeans = registerMultiItem(registry, new ItemCoffeeBean(Names.COFFEE_NAMES, BlockRegistry.coffeePlant), "coffee_beans", Names.COFFEE_NAMES);
    frogLeg = registerItem(registry, new ItemTropicraft().setMaxStackSize(64), "frog_leg");
    cookedFrogLeg = registerItem(registry, new ItemTropicraftFood(2, 0.15F), "cooked_frog_leg");
    poisonFrogSkin = registerItem(registry, new ItemTropicraft().setMaxStackSize(64), "poison_frog_skin");
    scale = registerItem(registry, new ItemTropicraft().setMaxStackSize(64), "scale");
    scaleBoots = registerItem(registry, new ItemScaleArmor(materialScaleArmor, 0, EntityEquipmentSlot.FEET), "scale_boots");
    scaleLeggings = registerItem(registry, new ItemScaleArmor(materialScaleArmor, 0, EntityEquipmentSlot.LEGS), "scale_leggings");
    scaleChestplate = registerItem(registry, new ItemScaleArmor(materialScaleArmor, 0, EntityEquipmentSlot.CHEST), "scale_chestplate");
    scaleHelmet = registerItem(registry, new ItemScaleArmor(materialScaleArmor, 0, EntityEquipmentSlot.HEAD), "scale_helmet");
    fireBoots = registerItem(registry, new ItemFireArmor(materialFireArmor, 0, EntityEquipmentSlot.FEET), "fire_boots");
    fireLeggings = registerItem(registry, new ItemFireArmor(materialFireArmor, 0, EntityEquipmentSlot.LEGS), "fire_leggings");
    fireChestplate = registerItem(registry, new ItemFireArmor(materialFireArmor, 0, EntityEquipmentSlot.CHEST), "fire_chestplate");
    fireHelmet = registerItem(registry, new ItemFireArmor(materialFireArmor, 0, EntityEquipmentSlot.HEAD), "fire_helmet");
    chair = registerMultiItem(registry, new ItemChair(), "chair", ItemDye.DYE_COLORS.length);
    umbrella = registerMultiItem(registry, new ItemUmbrella(), "umbrella", ItemDye.DYE_COLORS.length);
    beach_float = registerMultiItem(registry, new ItemBeachFloat(), "float", ItemDye.DYE_COLORS.length);
    portalEnchanter = registerItem(registry, new ItemPortalEnchanter(), "portal_enchanter");
    shell = registerMultiItem(registry, new ItemShell(), "shell", TropicraftShells.values());
    cocktail = registerMultiItem(registry, new ItemCocktail(), "cocktail", Drink.drinkList.length);
    whitePearl = registerItem(registry, new ItemTropicraft().setMaxStackSize(64), "white_pearl");
    blackPearl = registerItem(registry, new ItemTropicraft().setMaxStackSize(64), "black_pearl");
    fertilizer = registerItem(registry, new ItemFertilizer(), "fertilizer");
    encyclopedia = registerItem(registry, new ItemEncyclopediaTropica(), "encyclopedia_tropica");
    dagger = registerItem(registry, new ItemDagger(materialZirconTools), "dagger");
    bambooSpear = registerItem(registry, new ItemSword(materialBambooTools), "bamboo_spear");
    coconutBomb = registerItem(registry, new ItemCoconutBomb(), "coconut_bomb");
    flowerPot = registerItem(registry, new ItemTropicraftBlockSpecial(BlockRegistry.flowerPot), "flower_pot");
    bambooDoor = registerItem(registry, new ItemDoor(BlockRegistry.bambooDoor), "bamboo_door");
    bambooItemFrame = registerItem(registry, new ItemBambooItemFrame(EntityBambooItemFrame.class), "bamboo_item_frame");
    Tropicraft.proxy.registerArbitraryBlockVariants("bamboo_item_frame", "normal", "map");
    waterWand = registerItem(registry, new ItemWaterWand(), "water_wand");
    seaUrchinRoe = registerItem(registry, new ItemTropicraftFood(3, 0.3F), "sea_urchin_roe");
    mobEgg = registerMultiItemPrefixed(registry, new ItemMobEgg(), "spawn_egg", Names.EGG_NAMES);
    iguanaLeather = registerItem(registry, new ItemTropicraft().setMaxStackSize(64), "iguana_leather");
    OreDictionary.registerOre("leather", iguanaLeather);
    trimix = registerItem(registry, new ItemTropicraft().setMaxStackSize(1), "trimix");
    maskSquareZord = registerItem(registry, new ItemAshenMask(materialMaskArmor, 0, EntityEquipmentSlot.HEAD, AshenMasks.SQUARE_ZORD), "mask_square_zord");
    maskHornMonkey = registerItem(registry, new ItemAshenMask(materialMaskArmor, 0, EntityEquipmentSlot.HEAD, AshenMasks.HORN_MONKEY), "mask_horn_monkey");
    maskOblongatron = registerItem(registry, new ItemAshenMask(materialMaskArmor, 0, EntityEquipmentSlot.HEAD, AshenMasks.OBLONGATRON), "mask_oblongatron");
    maskHeadinator = registerItem(registry, new ItemAshenMask(materialMaskArmor, 0, EntityEquipmentSlot.HEAD, AshenMasks.HEADINATOR), "mask_headinator");
    maskSquareHorn = registerItem(registry, new ItemAshenMask(materialMaskArmor, 0, EntityEquipmentSlot.HEAD, AshenMasks.SQUARE_HORN), "mask_square_horn");
    maskScrewAttack = registerItem(registry, new ItemAshenMask(materialMaskArmor, 0, EntityEquipmentSlot.HEAD, AshenMasks.SCREW_ATTACK), "mask_screw_attack");
    maskTheBrain = registerItem(registry, new ItemAshenMask(materialMaskArmor, 0, EntityEquipmentSlot.HEAD, AshenMasks.THE_BRAIN), "mask_the_brain");
    maskBatBoy = registerItem(registry, new ItemAshenMask(materialMaskArmor, 0, EntityEquipmentSlot.HEAD, AshenMasks.BAT_BOY), "mask_bat_boy");
    mask1 = registerItem(registry, new ItemAshenMask(materialMaskArmor, 0, EntityEquipmentSlot.HEAD, AshenMasks.ASHEN_MASK1), "mask_ashen_mask1");
    mask2 = registerItem(registry, new ItemAshenMask(materialMaskArmor, 0, EntityEquipmentSlot.HEAD, AshenMasks.ASHEN_MASK2), "mask_ashen_mask2");
    mask3 = registerItem(registry, new ItemAshenMask(materialMaskArmor, 0, EntityEquipmentSlot.HEAD, AshenMasks.ASHEN_MASK3), "mask_ashen_mask3");
    mask4 = registerItem(registry, new ItemAshenMask(materialMaskArmor, 0, EntityEquipmentSlot.HEAD, AshenMasks.ASHEN_MASK4), "mask_ashen_mask4");
    mask5 = registerItem(registry, new ItemAshenMask(materialMaskArmor, 0, EntityEquipmentSlot.HEAD, AshenMasks.ASHEN_MASK5), "mask_ashen_mask5");
    fishingRod = registerItem(registry, new ItemFishingRod(), "fishing_rod");
    ltShell = registerMultiItem(registry, new ItemLoveTropicsShell(), "ltshell", Names.LOVE_TROPICS_NAMES.length);
}
Also used : ItemPortalEnchanter(net.tropicraft.core.common.item.ItemPortalEnchanter) ItemDoor(net.minecraft.item.ItemDoor) ItemFertilizer(net.tropicraft.core.common.item.ItemFertilizer) ItemCocktail(net.tropicraft.core.common.item.ItemCocktail) ItemScubaChestplateGear(net.tropicraft.core.common.item.scuba.ItemScubaChestplateGear) ItemBCD(net.tropicraft.core.common.item.scuba.ItemBCD) ItemTropicraftBlockSpecial(net.tropicraft.core.common.item.ItemTropicraftBlockSpecial) ItemDiveComputer(net.tropicraft.core.common.item.scuba.ItemDiveComputer) ItemCoconutBomb(net.tropicraft.core.common.item.ItemCoconutBomb) ItemAshenMask(net.tropicraft.core.common.item.armor.ItemAshenMask) ItemWaterWand(net.tropicraft.core.common.item.ItemWaterWand) ItemChair(net.tropicraft.core.common.item.ItemChair) Item(net.minecraft.item.Item) ItemHoe(net.minecraft.item.ItemHoe) ItemSpade(net.minecraft.item.ItemSpade) ItemTropicraftPickaxe(net.tropicraft.core.common.item.ItemTropicraftPickaxe) ItemScaleArmor(net.tropicraft.core.common.item.armor.ItemScaleArmor) ItemShell(net.tropicraft.core.common.item.ItemShell) ItemCoffeeBean(net.tropicraft.core.common.item.ItemCoffeeBean) ItemFishBucket(net.tropicraft.core.common.item.ItemFishBucket) ItemTropicraft(net.tropicraft.core.common.item.ItemTropicraft) ItemMusicDisc(net.tropicraft.core.common.item.ItemMusicDisc) ItemSword(net.minecraft.item.ItemSword) ItemFireArmor(net.tropicraft.core.common.item.armor.ItemFireArmor) ItemTropicsOre(net.tropicraft.core.common.item.ItemTropicsOre) ItemFishingRod(net.tropicraft.core.common.item.ItemFishingRod) ItemScubaTank(net.tropicraft.core.common.item.scuba.ItemScubaTank) ItemTropicraftFood(net.tropicraft.core.common.item.ItemTropicraftFood) ItemBucket(net.minecraft.item.ItemBucket) ItemBeachFloat(net.tropicraft.core.common.item.ItemBeachFloat) ItemScubaFlippers(net.tropicraft.core.common.item.scuba.ItemScubaFlippers) ItemLoveTropicsShell(net.tropicraft.core.common.item.ItemLoveTropicsShell) ItemUmbrella(net.tropicraft.core.common.item.ItemUmbrella) ItemTropicraftAxe(net.tropicraft.core.common.item.ItemTropicraftAxe) ItemEncyclopediaTropica(net.tropicraft.core.common.item.ItemEncyclopediaTropica) ItemMobEgg(net.tropicraft.core.common.item.ItemMobEgg) ItemScubaHelmet(net.tropicraft.core.common.item.scuba.ItemScubaHelmet) ItemPonyBottle(net.tropicraft.core.common.item.scuba.ItemPonyBottle) ItemBambooItemFrame(net.tropicraft.core.common.item.ItemBambooItemFrame) ItemDagger(net.tropicraft.core.common.item.ItemDagger) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with ItemDoor

use of net.minecraft.item.ItemDoor in project SpongeForge by SpongePowered.

the class MixinPlayerInteractionManager method processRightClickBlock.

/**
 * @author gabizou - May 5th, 2016
 * @reason Rewrite the firing of interact block events with forge hooks
 * Note: This is a dirty merge of Aaron's SpongeCommon writeup of the interaction events and
 * Forge's additions. There's some overlay between the two events, specifically that there
 * is a SpongeEvent thrown before the ForgeEvent, and yet both are checked in various
 * if statements.
 */
@Overwrite
public EnumActionResult processRightClickBlock(EntityPlayer player, World worldIn, ItemStack stack, EnumHand hand, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (this.gameType == GameType.SPECTATOR) {
        TileEntity tileentity = worldIn.getTileEntity(pos);
        if (tileentity instanceof ILockableContainer) {
            Block block = worldIn.getBlockState(pos).getBlock();
            ILockableContainer ilockablecontainer = (ILockableContainer) tileentity;
            if (ilockablecontainer instanceof TileEntityChest && block instanceof BlockChest) {
                ilockablecontainer = ((BlockChest) block).getLockableContainer(worldIn, pos);
            }
            if (ilockablecontainer != null) {
                player.displayGUIChest(ilockablecontainer);
                return EnumActionResult.SUCCESS;
            }
        } else if (tileentity instanceof IInventory) {
            player.displayGUIChest((IInventory) tileentity);
            return EnumActionResult.SUCCESS;
        }
        return EnumActionResult.PASS;
    }
    // Store reference of current player's itemstack in case it changes
    ItemStack oldStack = stack.copy();
    InteractBlockEvent.Secondary event;
    BlockSnapshot currentSnapshot = ((org.spongepowered.api.world.World) worldIn).createSnapshot(pos.getX(), pos.getY(), pos.getZ());
    event = SpongeCommonEventFactory.callInteractBlockEventSecondary(player, oldStack, VecHelper.toVector3d(pos.add(hitX, hitY, hitZ)), currentSnapshot, DirectionFacingProvider.getInstance().getKey(facing).get(), hand);
    if (!ItemStack.areItemStacksEqual(oldStack, this.player.getHeldItem(hand))) {
        SpongeCommonEventFactory.playerInteractItemChanged = true;
    }
    TileEntity tileEntity = worldIn.getTileEntity(pos);
    if (event.isCancelled()) {
        final IBlockState state = worldIn.getBlockState(pos);
        if (state.getBlock() == Blocks.COMMAND_BLOCK) {
            // CommandBlock GUI opens solely on the client, we need to force it close on cancellation
            this.player.connection.sendPacket(new SPacketCloseWindow(0));
        } else if (state.getProperties().containsKey(BlockDoor.HALF)) {
            // client to resolve this
            if (state.getValue(BlockDoor.HALF) == BlockDoor.EnumDoorHalf.LOWER) {
                this.player.connection.sendPacket(new SPacketBlockChange(worldIn, pos.up()));
            } else {
                this.player.connection.sendPacket(new SPacketBlockChange(worldIn, pos.down()));
            }
        } else if (!stack.isEmpty()) {
            // Stopping the placement of a door or double plant causes artifacts (ghosts) on the top-side of the block. We need to remove it
            if (stack.getItem() instanceof ItemDoor || (stack.getItem() instanceof ItemBlock && ((ItemBlock) stack.getItem()).getBlock().equals(Blocks.DOUBLE_PLANT))) {
                this.player.connection.sendPacket(new SPacketBlockChange(worldIn, pos.up(2)));
            }
        }
        // since we don't want to undo that
        if (tileEntity != null && this.player.openContainer instanceof ContainerPlayer) {
            this.player.closeScreen();
        }
        SpongeCommonEventFactory.interactBlockEventCancelled = true;
        return EnumActionResult.FAIL;
    }
    net.minecraft.item.Item item = stack.isEmpty() ? null : stack.getItem();
    EnumActionResult ret = item == null ? EnumActionResult.PASS : item.onItemUseFirst(player, worldIn, pos, facing, hitX, hitY, hitZ, hand);
    if (ret != EnumActionResult.PASS) {
        return ret;
    }
    boolean bypass = true;
    final ItemStack[] itemStacks = { player.getHeldItemMainhand(), player.getHeldItemOffhand() };
    for (ItemStack s : itemStacks) {
        bypass = bypass && (s.isEmpty() || s.getItem().doesSneakBypassUse(s, worldIn, pos, player));
    }
    EnumActionResult result = EnumActionResult.PASS;
    if (!player.isSneaking() || bypass || event.getUseBlockResult() == Tristate.TRUE) {
        // also, store the result instead of returning immediately
        if (event.getUseBlockResult() != Tristate.FALSE) {
            IBlockState iblockstate = worldIn.getBlockState(pos);
            Container lastOpenContainer = player.openContainer;
            result = iblockstate.getBlock().onBlockActivated(worldIn, pos, iblockstate, player, hand, facing, hitX, hitY, hitZ) ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
            // if itemstack changed, avoid restore
            if (!ItemStack.areItemStacksEqual(oldStack, this.player.getHeldItem(hand))) {
                SpongeCommonEventFactory.playerInteractItemChanged = true;
            }
            result = this.handleOpenEvent(lastOpenContainer, this.player, currentSnapshot, result);
        } else {
            this.player.connection.sendPacket(new SPacketBlockChange(this.world, pos));
            result = TristateUtil.toActionResult(event.getUseItemResult());
        }
    }
    // This handles the event not cancelled and block not activated
    if (result != EnumActionResult.SUCCESS && tileEntity != null && hand == EnumHand.MAIN_HAND) {
        this.player.closeScreen();
    }
    // store result instead of returning
    if (stack.isEmpty()) {
        result = EnumActionResult.PASS;
    } else if (player.getCooldownTracker().hasCooldown(stack.getItem())) {
        result = EnumActionResult.PASS;
    } else if (stack.getItem() instanceof ItemBlock && ((ItemBlock) stack.getItem()).getBlock() instanceof BlockCommandBlock && !player.canUseCommand(2, "")) {
        result = EnumActionResult.FAIL;
    } else {
        if ((result != EnumActionResult.SUCCESS && event.getUseItemResult() != Tristate.FALSE || result == EnumActionResult.SUCCESS && event.getUseItemResult() == Tristate.TRUE)) {
            int meta = stack.getMetadata();
            int size = stack.getCount();
            result = stack.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
            // nest isCreative check instead of calling the method twice.
            if (this.isCreative()) {
                stack.setItemDamage(meta);
                stack.setCount(size);
            }
        }
    }
    if (!ItemStack.areItemStacksEqual(player.getHeldItem(hand), oldStack) || result != EnumActionResult.SUCCESS) {
        player.openContainer.detectAndSendChanges();
    }
    return result;
// Sponge end
}
Also used : ItemDoor(net.minecraft.item.ItemDoor) BlockCommandBlock(net.minecraft.block.BlockCommandBlock) World(net.minecraft.world.World) TileEntity(net.minecraft.tileentity.TileEntity) ILockableContainer(net.minecraft.world.ILockableContainer) EnumActionResult(net.minecraft.util.EnumActionResult) ILockableContainer(net.minecraft.world.ILockableContainer) Container(net.minecraft.inventory.Container) InteractBlockEvent(org.spongepowered.api.event.block.InteractBlockEvent) SPacketCloseWindow(net.minecraft.network.play.server.SPacketCloseWindow) IInventory(net.minecraft.inventory.IInventory) TileEntityChest(net.minecraft.tileentity.TileEntityChest) IBlockState(net.minecraft.block.state.IBlockState) BlockChest(net.minecraft.block.BlockChest) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ItemBlock(net.minecraft.item.ItemBlock) SPacketBlockChange(net.minecraft.network.play.server.SPacketBlockChange) ContainerPlayer(net.minecraft.inventory.ContainerPlayer) Block(net.minecraft.block.Block) BlockCommandBlock(net.minecraft.block.BlockCommandBlock) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 3 with ItemDoor

use of net.minecraft.item.ItemDoor in project SpongeCommon by SpongePowered.

the class MixinPlayerInteractionManager method processRightClickBlock.

/**
 * @author Aaron1011
 * @author gabizou - May 28th, 2016 - Rewritten for 1.9.4
 *
 * @reason Fire interact block event.
 */
@Overwrite
public EnumActionResult processRightClickBlock(EntityPlayer player, net.minecraft.world.World worldIn, ItemStack stack, EnumHand hand, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (this.gameType == GameType.SPECTATOR) {
        TileEntity tileentity = worldIn.getTileEntity(pos);
        if (tileentity instanceof ILockableContainer) {
            Block block = worldIn.getBlockState(pos).getBlock();
            ILockableContainer ilockablecontainer = (ILockableContainer) tileentity;
            if (ilockablecontainer instanceof TileEntityChest && block instanceof BlockChest) {
                ilockablecontainer = ((BlockChest) block).getLockableContainer(worldIn, pos);
            }
            if (ilockablecontainer != null) {
                // TODO - fire event
                player.displayGUIChest(ilockablecontainer);
                return EnumActionResult.SUCCESS;
            }
        } else if (tileentity instanceof IInventory) {
            // TODO - fire event
            player.displayGUIChest((IInventory) tileentity);
            return EnumActionResult.SUCCESS;
        }
        return EnumActionResult.PASS;
    }
    // else { // Sponge - Remove unecessary else
    // Sponge Start - Create an interact block event before something happens.
    final ItemStack oldStack = stack.copy();
    final BlockSnapshot currentSnapshot = ((World) worldIn).createSnapshot(pos.getX(), pos.getY(), pos.getZ());
    final InteractBlockEvent.Secondary event = SpongeCommonEventFactory.callInteractBlockEventSecondary(player, oldStack, new Vector3d(pos.getX() + hitX, pos.getY() + hitY, pos.getZ() + hitZ), currentSnapshot, DirectionFacingProvider.getInstance().getKey(facing).get(), hand);
    if (!ItemStack.areItemStacksEqual(oldStack, this.player.getHeldItem(hand))) {
        SpongeCommonEventFactory.playerInteractItemChanged = true;
    }
    if (event.isCancelled()) {
        final IBlockState state = (IBlockState) currentSnapshot.getState();
        if (state.getBlock() == Blocks.COMMAND_BLOCK) {
            // CommandBlock GUI opens solely on the client, we need to force it close on cancellation
            this.player.connection.sendPacket(new SPacketCloseWindow(0));
        } else if (state.getProperties().containsKey(BlockDoor.HALF)) {
            // client to resolve this
            if (state.getValue(BlockDoor.HALF) == BlockDoor.EnumDoorHalf.LOWER) {
                this.player.connection.sendPacket(new SPacketBlockChange(worldIn, pos.up()));
            } else {
                this.player.connection.sendPacket(new SPacketBlockChange(worldIn, pos.down()));
            }
        } else if (!oldStack.isEmpty()) {
            // Stopping the placement of a door or double plant causes artifacts (ghosts) on the top-side of the block. We need to remove it
            final Item item = oldStack.getItem();
            if (item instanceof ItemDoor || (item instanceof ItemBlock && ((ItemBlock) item).getBlock().equals(Blocks.DOUBLE_PLANT))) {
                this.player.connection.sendPacket(new SPacketBlockChange(worldIn, pos.up(2)));
            }
        }
        SpongeCommonEventFactory.interactBlockEventCancelled = true;
        return EnumActionResult.FAIL;
    }
    if (!player.isSneaking() || player.getHeldItemMainhand().isEmpty() && player.getHeldItemOffhand().isEmpty()) {
        // Also, store the result instead of returning immediately
        if (event.getUseBlockResult() != Tristate.FALSE) {
            IBlockState iblockstate = (IBlockState) currentSnapshot.getState();
            Container lastOpenContainer = player.openContainer;
            EnumActionResult result = iblockstate.getBlock().onBlockActivated(worldIn, pos, iblockstate, player, hand, facing, hitX, hitY, hitZ) ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
            // if itemstack changed, avoid restore
            if (!ItemStack.areItemStacksEqual(oldStack, this.player.getHeldItem(hand))) {
                SpongeCommonEventFactory.playerInteractItemChanged = true;
            }
            result = this.handleOpenEvent(lastOpenContainer, this.player, currentSnapshot, result);
            if (result != EnumActionResult.PASS) {
                return result;
            }
        } else {
            // Need to send a block change to the client, because otherwise, they are not
            // going to be told about the block change.
            this.player.connection.sendPacket(new SPacketBlockChange(this.world, pos));
            // it wasn't cancelled, but perform no further processing.
            return EnumActionResult.FAIL;
        }
    // Sponge End
    }
    if (stack.isEmpty()) {
        return EnumActionResult.PASS;
    } else if (player.getCooldownTracker().hasCooldown(stack.getItem())) {
        return EnumActionResult.PASS;
    } else if (stack.getItem() instanceof ItemBlock) {
        Block block = ((ItemBlock) stack.getItem()).getBlock();
        if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !player.canUseCommandBlock()) {
            return EnumActionResult.FAIL;
        }
    }
    // else if (this.isCreative()) { // Sponge - Rewrite this to handle an isCreative check after the result, since we have a copied stack at the top of this method.
    // int j = stack.getMetadata();
    // int i = stack.stackSize;
    // EnumActionResult enumactionresult = stack.onItemUse(player, worldIn, pos, hand, facing, offsetX, offsetY, offsetZ);
    // stack.setItemDamage(j);
    // stack.stackSize = i;
    // return enumactionresult;
    // } else {
    // return stack.onItemUse(player, worldIn, pos, hand, facing, offsetX, offsetY, offsetZ);
    // }
    // } // Sponge - Remove unecessary else bracket
    // Sponge Start - complete the method with the micro change of resetting item damage and quantity from the copied stack.
    final EnumActionResult result = stack.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
    if (this.isCreative()) {
        stack.setItemDamage(oldStack.getItemDamage());
        stack.setCount(oldStack.getCount());
    }
    if (!ItemStack.areItemStacksEqual(player.getHeldItem(hand), oldStack) || result != EnumActionResult.SUCCESS) {
        player.openContainer.detectAndSendChanges();
    }
    return result;
// Sponge end
// } // Sponge - Remove unecessary else bracket
}
Also used : IInventory(net.minecraft.inventory.IInventory) TileEntityChest(net.minecraft.tileentity.TileEntityChest) IBlockState(net.minecraft.block.state.IBlockState) ItemDoor(net.minecraft.item.ItemDoor) BlockChest(net.minecraft.block.BlockChest) BlockCommandBlock(net.minecraft.block.BlockCommandBlock) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) BlockStructure(net.minecraft.block.BlockStructure) World(org.spongepowered.api.world.World) ItemBlock(net.minecraft.item.ItemBlock) SPacketBlockChange(net.minecraft.network.play.server.SPacketBlockChange) TileEntity(net.minecraft.tileentity.TileEntity) ILockableContainer(net.minecraft.world.ILockableContainer) Item(net.minecraft.item.Item) ILockableContainer(net.minecraft.world.ILockableContainer) IMixinContainer(org.spongepowered.common.interfaces.IMixinContainer) Container(net.minecraft.inventory.Container) EnumActionResult(net.minecraft.util.EnumActionResult) InteractBlockEvent(org.spongepowered.api.event.block.InteractBlockEvent) Vector3d(com.flowpowered.math.vector.Vector3d) Block(net.minecraft.block.Block) BlockCommandBlock(net.minecraft.block.BlockCommandBlock) ItemBlock(net.minecraft.item.ItemBlock) SPacketCloseWindow(net.minecraft.network.play.server.SPacketCloseWindow) ItemStack(net.minecraft.item.ItemStack) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 4 with ItemDoor

use of net.minecraft.item.ItemDoor in project BiomesOPlenty by Glitchfiend.

the class ModBlocks method registerDoor.

// use a separate function for registering doors because the door block and item need to be registered together
public static Block registerDoor(BlockBOPDoor door_block, String name, Item door_item) {
    Block block = registerBlock(door_block, name + "_block", null, false);
    door_item = ModItems.registerItem(new ItemDoor(block), name);
    door_block.setDoorItem(door_item);
    return block;
}
Also used : ItemDoor(net.minecraft.item.ItemDoor) BlockBOPBiomeBlock(biomesoplenty.common.block.BlockBOPBiomeBlock) Block(net.minecraft.block.Block) IBOPBlock(biomesoplenty.common.block.IBOPBlock) ItemBlock(net.minecraft.item.ItemBlock)

Aggregations

ItemDoor (net.minecraft.item.ItemDoor)4 Block (net.minecraft.block.Block)3 ItemBlock (net.minecraft.item.ItemBlock)3 BlockChest (net.minecraft.block.BlockChest)2 BlockCommandBlock (net.minecraft.block.BlockCommandBlock)2 IBlockState (net.minecraft.block.state.IBlockState)2 Container (net.minecraft.inventory.Container)2 IInventory (net.minecraft.inventory.IInventory)2 Item (net.minecraft.item.Item)2 ItemStack (net.minecraft.item.ItemStack)2 SPacketBlockChange (net.minecraft.network.play.server.SPacketBlockChange)2 SPacketCloseWindow (net.minecraft.network.play.server.SPacketCloseWindow)2 TileEntity (net.minecraft.tileentity.TileEntity)2 TileEntityChest (net.minecraft.tileentity.TileEntityChest)2 EnumActionResult (net.minecraft.util.EnumActionResult)2 ILockableContainer (net.minecraft.world.ILockableContainer)2 BlockBOPBiomeBlock (biomesoplenty.common.block.BlockBOPBiomeBlock)1 IBOPBlock (biomesoplenty.common.block.IBOPBlock)1 Vector3d (com.flowpowered.math.vector.Vector3d)1 BlockStructure (net.minecraft.block.BlockStructure)1