Search in sources :

Example 51 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project Geolosys by oitsjustjose.

the class BlockColorInit method registerBlockColors.

@SubscribeEvent
public static void registerBlockColors(ColorHandlerEvent.Block evt) {
    BlockColors blockColors = evt.getBlockColors();
    blockColors.register((unknown, lightReader, pos, unknown2) -> lightReader != null && pos != null ? BiomeColors.getGrassColor(lightReader, pos) : GrassColors.get(0.5D, 1.0D), ModBlocks.getInstance().peat);
    blockColors.register((unknown, lightReader, pos, unknown2) -> lightReader != null && pos != null ? BiomeColors.getGrassColor(lightReader, pos) : GrassColors.get(0.5D, 1.0D), ModBlocks.getInstance().rhododendron);
}
Also used : BlockColors(net.minecraft.client.renderer.color.BlockColors) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 52 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project Geolosys by oitsjustjose.

the class BlockColorInit method registerItemColors.

@SubscribeEvent
public static void registerItemColors(ColorHandlerEvent.Item evt) {
    final BlockColors blockColors = evt.getBlockColors();
    final ItemColors itemColors = evt.getItemColors();
    // Use the Block's colour handler for an ItemBlock
    IItemColor itemBlockColourHandler = (stack, tintIndex) -> {
        BlockState state = ((BlockItem) stack.getItem()).getBlock().getDefaultState();
        return blockColors.getColor(state, null, null, tintIndex);
    };
    if (itemBlockColourHandler != null) {
        itemColors.register(itemBlockColourHandler, ModBlocks.getInstance().peat);
        itemColors.register(itemBlockColourHandler, ModBlocks.getInstance().rhododendron);
    }
}
Also used : IItemColor(net.minecraft.client.renderer.color.IItemColor) BlockColors(net.minecraft.client.renderer.color.BlockColors) IItemColor(net.minecraft.client.renderer.color.IItemColor) BiomeColors(net.minecraft.world.biome.BiomeColors) ItemColors(net.minecraft.client.renderer.color.ItemColors) BlockItem(net.minecraft.item.BlockItem) GrassColors(net.minecraft.world.GrassColors) Mod(net.minecraftforge.fml.common.Mod) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) BlockState(net.minecraft.block.BlockState) ColorHandlerEvent(net.minecraftforge.client.event.ColorHandlerEvent) ModBlocks(com.oitsjustjose.geolosys.common.blocks.ModBlocks) Dist(net.minecraftforge.api.distmarker.Dist) BlockState(net.minecraft.block.BlockState) ItemColors(net.minecraft.client.renderer.color.ItemColors) BlockColors(net.minecraft.client.renderer.color.BlockColors) BlockItem(net.minecraft.item.BlockItem) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 53 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project NetherEx by LogicTechCorp.

the class PlayerHandler method onPlayerDrop.

@SubscribeEvent
public static void onPlayerDrop(LivingDropsEvent event) {
    LivingEntity livingEntity = event.getEntityLiving();
    Iterator<ItemEntity> iter = event.getDrops().iterator();
    if (livingEntity instanceof PlayerEntity) {
        PlayerEntity player = (PlayerEntity) livingEntity;
        while (iter.hasNext()) {
            ItemEntity entityItem = iter.next();
            ItemStack stack = entityItem.getItem();
            if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
                player.setItemStackToSlot(EquipmentSlotType.MAINHAND, stack);
                iter.remove();
                break;
            }
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 54 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project NetherEx by LogicTechCorp.

the class PlayerHandler method onPlayerRespawn.

@SubscribeEvent
public static void onPlayerRespawn(PlayerEvent.PlayerRespawnEvent event) {
    World world = event.getPlayer().getEntityWorld();
    PlayerEntity player = event.getPlayer();
    PlayerInventory playerInventory = player.inventory;
    if (!world.isRemote) {
        ItemStack mirrorStack = ItemStack.EMPTY;
        for (int i = 0; i < playerInventory.getSizeInventory(); i++) {
            ItemStack stack = playerInventory.getStackInSlot(i);
            if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
                mirrorStack = stack;
                break;
            }
        }
        if (!mirrorStack.isEmpty()) {
            if (mirrorStack.getDamage() < mirrorStack.getMaxDamage() - 1) {
                CompoundNBT compound = NBTHelper.ensureTagExists(mirrorStack);
                if (compound.contains("SpawnDimension") && compound.contains("SpawnPoint")) {
                    DimensionType spawnDimension = DimensionType.byName(new ResourceLocation(compound.getString("SpawnDimension")));
                    if (spawnDimension != null && player.dimension != spawnDimension) {
                        MinecraftServer server = world.getServer();
                        if (server != null) {
                            BlockPos spawnPoint = NBTUtil.readBlockPos(compound.getCompound("SpawnPoint"));
                            ((ServerPlayerEntity) player).teleport(server.getWorld(spawnDimension), spawnPoint.getX() + 0.5D, spawnPoint.getY(), spawnPoint.getZ() + 0.5D, player.rotationYaw, player.rotationPitch);
                        }
                    }
                }
            }
        }
    }
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) CompoundNBT(net.minecraft.nbt.CompoundNBT) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.math.BlockPos) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) PlayerInventory(net.minecraft.entity.player.PlayerInventory) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) MinecraftServer(net.minecraft.server.MinecraftServer) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 55 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project NetherEx by LogicTechCorp.

the class PlayerHandler method onItemCrafted.

@SubscribeEvent
public static void onItemCrafted(PlayerEvent.ItemCraftedEvent event) {
    PlayerEntity player = event.getPlayer();
    ItemStack stack = event.getCrafting();
    if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
        if (stack.getDamage() < stack.getMaxDamage()) {
            CompoundNBT compound = NBTHelper.ensureTagExists(stack);
            compound.putBoolean("RemovedSpawn", false);
            if (compound.contains("SpawnDimension") && compound.contains("SpawnPoint")) {
                DimensionType spawnDimension = DimensionType.byName(new ResourceLocation(compound.getString("SpawnDimension")));
                BlockPos spawnPoint = NBTUtil.readBlockPos(compound.getCompound("SpawnPoint"));
                if (spawnDimension != null) {
                    player.setSpawnDimenion(spawnDimension);
                    player.setSpawnPoint(spawnPoint, true, false, spawnDimension);
                }
            }
        }
    }
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) CompoundNBT(net.minecraft.nbt.CompoundNBT) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)87 PlayerEntity (net.minecraft.entity.player.PlayerEntity)18 ItemStack (net.minecraft.item.ItemStack)17 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)11 ResourceLocation (net.minecraft.util.ResourceLocation)10 World (net.minecraft.world.World)8 Player (net.minecraft.world.entity.player.Player)8 BlockPos (net.minecraft.util.math.BlockPos)7 Entity (net.minecraft.world.entity.Entity)7 ItemStack (net.minecraft.world.item.ItemStack)7 CompoundNBT (net.minecraft.nbt.CompoundNBT)6 Minecraft (net.minecraft.client.Minecraft)5 BlockPos (net.minecraft.core.BlockPos)5 ServerPlayer (net.minecraft.server.level.ServerPlayer)5 StringTextComponent (net.minecraft.util.text.StringTextComponent)5 Item (net.minecraft.world.item.Item)5 BlockItem (net.minecraft.item.BlockItem)4 ResourceLocation (net.minecraft.resources.ResourceLocation)4 BlockState (net.minecraft.world.level.block.state.BlockState)4 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)4