Search in sources :

Example 11 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project Overloaded by CJ-MC-Mods.

the class ResizeableTextureGenerator method texturePre.

@SubscribeEvent
public void texturePre(@Nonnull TextureStitchEvent.Pre event) {
    if (!event.getMap().location().getPath().equals("textures")) {
        return;
    }
    event.addSprite(new ResourceLocation(MODID, "item/multi_right_arm"));
    event.addSprite(new ResourceLocation(MODID, "item/multi_left_arm"));
    event.addSprite(new ResourceLocation(MODID, "item/multi_leg"));
    event.addSprite(new ResourceLocation(MODID, "item/multi_helmet"));
    event.addSprite(new ResourceLocation(MODID, "item/multi_body"));
    event.addSprite(new ResourceLocation(MODID, "item/multi_belt"));
    event.addSprite(new ResourceLocation(MODID, "item/multi_boot"));
    synchronized (toCreateTextures) {
        for (ResizableTexture resizableTexture : toCreateTextures) {
            BufferedImage image = null;
            try {
                image = ImageIO.read(getTextureInputStream(resizableTexture.originalTexture));
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (image == null)
                continue;
            image = ImageUtil.scaleDownToWidth(image, resizableTexture.resizeToWidth);
            BlockResourcePack.INSTANCE.addImage(resizableTexture.generatedName, image);
            event.getMap().getSprite(cleanForSprite(resizableTexture.generatedName));
        }
    }
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 12 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project Overloaded by CJ-MC-Mods.

the class RenderMultiToolAssist method renderWorldLastEvent.

@SubscribeEvent
public static void renderWorldLastEvent(RenderWorldLastEvent event) {
    float partialTick = Minecraft.getInstance().getFrameTime();
    PlayerEntity player = Minecraft.getInstance().player;
    if (player.getMainHandItem().getItem() != ModItems.multiTool)
        return;
    RayTraceResult resultPick = player.pick(OverloadedConfig.INSTANCE.multiToolConfig.reach, partialTick, false);
    if (resultPick.getType() == RayTraceResult.Type.MISS || !(resultPick instanceof BlockRayTraceResult)) {
        return;
    }
    BlockRayTraceResult result = ((BlockRayTraceResult) resultPick);
    ItemStack stack = ModItems.multiTool.getSelectedBlockItemStack(player.getMainHandItem());
    BlockState state;
    if (stack.getItem() instanceof BlockItem) {
        state = ((BlockItem) stack.getItem()).getBlock().defaultBlockState();
        state = state.getStateAtViewpoint(player.getCommandSenderWorld(), result.getBlockPos(), player.getEyePosition(partialTick));
        state = state.getBlock().getStateForPlacement(new BlockItemUseContextPublic(player.getCommandSenderWorld(), player, Hand.MAIN_HAND, stack, result));
    } else {
        state = Blocks.COBBLESTONE.defaultBlockState();
    }
    switch(getAssistMode()) {
        case PLACE_PREVIEW:
            if (!stack.isEmpty() && state != null)
                renderBlockPreview(event, result, state);
            break;
        case REMOVE_PREVIEW:
            renderRemovePreview(event, result);
            break;
        case BOTH_PREVIEW:
            renderRemovePreview(event, result);
            if (!stack.isEmpty() && state != null)
                renderBlockPreview(event, result, state);
    }
}
Also used : BlockState(net.minecraft.block.BlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) ItemStack(net.minecraft.item.ItemStack) BlockItem(net.minecraft.item.BlockItem) BlockItemUseContextPublic(com.cjm721.overloaded.util.BlockItemUseContextPublic) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 13 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project MinecraftForge by MinecraftForge.

the class ForgeMod method registerRecipeSerialziers.

// ModBus, can't use addListener due to nested genetics.
@SubscribeEvent
public void registerRecipeSerialziers(RegistryEvent.Register<RecipeSerializer<?>> event) {
    CraftingHelper.register(AndCondition.Serializer.INSTANCE);
    CraftingHelper.register(FalseCondition.Serializer.INSTANCE);
    CraftingHelper.register(ItemExistsCondition.Serializer.INSTANCE);
    CraftingHelper.register(ModLoadedCondition.Serializer.INSTANCE);
    CraftingHelper.register(NotCondition.Serializer.INSTANCE);
    CraftingHelper.register(OrCondition.Serializer.INSTANCE);
    CraftingHelper.register(TrueCondition.Serializer.INSTANCE);
    CraftingHelper.register(TagEmptyCondition.Serializer.INSTANCE);
    CraftingHelper.register(new ResourceLocation("forge", "compound"), CompoundIngredient.Serializer.INSTANCE);
    CraftingHelper.register(new ResourceLocation("forge", "nbt"), NBTIngredient.Serializer.INSTANCE);
    CraftingHelper.register(new ResourceLocation("minecraft", "item"), VanillaIngredientSerializer.INSTANCE);
    event.getRegistry().register(new ConditionalRecipe.Serializer<Recipe<?>>().setRegistryName(new ResourceLocation("forge", "conditional")));
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) VanillaIngredientSerializer(net.minecraftforge.common.crafting.VanillaIngredientSerializer) ArgumentSerializer(net.minecraft.commands.synchronization.ArgumentSerializer) EmptyArgumentSerializer(net.minecraft.commands.synchronization.EmptyArgumentSerializer) GlobalLootModifierSerializer(net.minecraftforge.common.loot.GlobalLootModifierSerializer) RecipeSerializer(net.minecraft.world.item.crafting.RecipeSerializer) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 14 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project MinecraftForge by MinecraftForge.

the class FiniteWaterTest method handleFiniteWaterSource.

@SubscribeEvent
public static void handleFiniteWaterSource(BlockEvent.CreateFluidSourceEvent event) {
    if (ENABLED) {
        BlockState state = event.getState();
        FluidState fluidState = state.getFluidState();
        if (fluidState.getType().isSame(Fluids.WATER)) {
            event.setResult(Event.Result.DENY);
        } else if (fluidState.getType().isSame(Fluids.LAVA)) {
            event.setResult(Event.Result.ALLOW);
        }
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) FluidState(net.minecraft.world.level.material.FluidState) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 15 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project MinecraftForge by MinecraftForge.

the class PistonEventTest method pistonPre.

@SubscribeEvent
public static void pistonPre(PistonEvent.Pre event) {
    if (event.getPistonMoveType() == PistonMoveType.EXTEND) {
        Level world = (Level) event.getWorld();
        PistonStructureResolver pistonHelper = event.getStructureHelper();
        Player player = DistExecutor.safeCallWhenOn(Dist.CLIENT, () -> () -> Minecraft.getInstance().player);
        if (world.isClientSide && player != null) {
            if (pistonHelper.resolve()) {
                player.sendMessage(new TextComponent(String.format(Locale.ENGLISH, "Piston will extend moving %d blocks and destroy %d blocks", pistonHelper.getToPush().size(), pistonHelper.getToDestroy().size())), player.getUUID());
            } else {
                player.sendMessage(new TextComponent("Piston won't extend"), player.getUUID());
            }
        }
        if (pistonHelper.resolve()) {
            List<BlockPos> posList = pistonHelper.getToPush();
            for (BlockPos newPos : posList) {
                BlockState state = event.getWorld().getBlockState(newPos);
                if (state.getBlock() == Blocks.BLACK_WOOL) {
                    Block.dropResources(state, world, newPos);
                    world.setBlockAndUpdate(newPos, Blocks.AIR.defaultBlockState());
                }
            }
        }
        // Make the block move up and out of the way so long as it won't replace the piston
        BlockPos pushedBlockPos = event.getFaceOffsetPos();
        if (world.getBlockState(pushedBlockPos).getBlock() == shiftOnMove.get() && event.getDirection() != Direction.DOWN) {
            world.setBlockAndUpdate(pushedBlockPos, Blocks.AIR.defaultBlockState());
            world.setBlockAndUpdate(pushedBlockPos.above(), shiftOnMove.get().defaultBlockState());
        }
        // Block pushing cobblestone (directly, indirectly works)
        event.setCanceled(event.getWorld().getBlockState(event.getFaceOffsetPos()).getBlock() == Blocks.COBBLESTONE);
    } else {
        boolean isSticky = event.getWorld().getBlockState(event.getPos()).getBlock() == Blocks.STICKY_PISTON;
        Player player = DistExecutor.safeCallWhenOn(Dist.CLIENT, () -> () -> Minecraft.getInstance().player);
        if (event.getWorld().isClientSide() && player != null) {
            if (isSticky) {
                BlockPos targetPos = event.getFaceOffsetPos().relative(event.getDirection());
                boolean canPush = PistonBaseBlock.isPushable(event.getWorld().getBlockState(targetPos), (Level) event.getWorld(), event.getFaceOffsetPos(), event.getDirection().getOpposite(), false, event.getDirection());
                boolean isAir = event.getWorld().isEmptyBlock(targetPos);
                player.sendMessage(new TextComponent(String.format(Locale.ENGLISH, "Piston will retract moving %d blocks", !isAir && canPush ? 1 : 0)), player.getUUID());
            } else {
                player.sendMessage(new TextComponent("Piston will retract"), player.getUUID());
            }
        }
        // Offset twice to see if retraction will pull cobblestone
        event.setCanceled(event.getWorld().getBlockState(event.getFaceOffsetPos().relative(event.getDirection())).getBlock() == Blocks.COBBLESTONE && isSticky);
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) Player(net.minecraft.world.entity.player.Player) BlockState(net.minecraft.world.level.block.state.BlockState) PistonStructureResolver(net.minecraft.world.level.block.piston.PistonStructureResolver) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) 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