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));
}
}
}
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);
}
}
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")));
}
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);
}
}
}
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);
}
}
Aggregations