Skip to content

Commit

Permalink
whoops overwrote with 1.17
Browse files Browse the repository at this point in the history
  • Loading branch information
yurisuika committed Aug 28, 2023
1 parent 61a0a39 commit 44c5b29
Show file tree
Hide file tree
Showing 13 changed files with 272 additions and 164 deletions.
33 changes: 22 additions & 11 deletions src/main/java/dev/yurisuika/blossom/Blossom.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,21 @@
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.Identifier;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.ColorHandlerEvent;
import net.minecraftforge.client.event.ParticleFactoryRegisterEvent;
import net.minecraftforge.client.event.RegisterColorHandlersEvent;
import net.minecraftforge.client.event.RegisterParticleProvidersEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.CreativeModeTabEvent;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.EntityJoinLevelEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLPaths;
import net.minecraftforge.fmllegacy.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

import java.io.File;
import java.io.FileWriter;
Expand Down Expand Up @@ -284,7 +285,7 @@ public static void checkBounds() {

public static <T extends Block> RegistryObject<T> register(String name, Supplier<T> supplier, Item.Settings settings) {
RegistryObject<T> block = BLOCKS.register(name, supplier);
ITEMS.register(name, () -> new BlockItem(block.get(), settings.group(ItemGroup.DECORATIONS)));
ITEMS.register(name, () -> new BlockItem(block.get(), settings));
return block;
}

Expand All @@ -293,11 +294,11 @@ public static class CommonForgeEvents {

@SubscribeEvent
public static void registerCommandsEvents(RegisterCommandsEvent event) {
BlossomCommand.register(event.getDispatcher(), event.getEnvironment());
BlossomCommand.register(event.getDispatcher(), event.getBuildContext(), event.getCommandSelection());
}

@SubscribeEvent
public static void entityJoinWorldEvents(EntityJoinWorldEvent event) {
public static void entityJoinLevelEvents(EntityJoinLevelEvent event) {
Entity entity = event.getEntity();
if (entity instanceof BeeEntity) {
((BeeEntity)entity).getGoalSelector().add(4, new BlossomGoal((BeeEntity)entity));
Expand All @@ -320,7 +321,7 @@ public static void commonSetup(FMLCommonSetupEvent event) {
}

@SubscribeEvent
public static void particleFactoryRegisterEvents(ParticleFactoryRegisterEvent event) {
public static void registerParticleProvidersEvents(RegisterParticleProvidersEvent event) {
MinecraftClient.getInstance().particleManager.registerFactory(BLOSSOM.get(), BlossomParticle.Factory::new);
}

Expand Down Expand Up @@ -356,17 +357,27 @@ public static void clientSetup(FMLClientSetupEvent event) {
}

@SubscribeEvent
public static void blockColorHandlerEvents(ColorHandlerEvent.Block event) {
public static void registerBlockColorHandlersEvents(RegisterColorHandlersEvent.Block event) {
event.getBlockColors().registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getFoliageColor(world, pos) : FoliageColors.getColor(0.5, 1.0), Blossom.FLOWERING_OAK_LEAVES.get());
event.getBlockColors().registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getFoliageColor(world, pos) : FoliageColors.getColor(0.5, 1.0), Blossom.FRUITING_OAK_LEAVES.get());
}

@SubscribeEvent
public static void itemColorHandlerEvents(ColorHandlerEvent.Item event) {
event.getItemColors().register((stack, tintIndex) -> tintIndex > 0 ? -1 : MinecraftClient.getInstance().getBlockColors().getColor(((BlockItem) stack.getItem()).getBlock().getDefaultState(), null, null, tintIndex), Blossom.FLOWERING_OAK_LEAVES.get());
public static void registerItemColorHandlersEvents(RegisterColorHandlersEvent.Item event) {
event.getItemColors().register((stack, tintIndex) -> tintIndex > 0 ? -1 : MinecraftClient.getInstance().getBlockColors().getColor(((BlockItem) stack.getItem()).getBlock().getDefaultState(), null, null, tintIndex), FLOWERING_OAK_LEAVES.get());
event.getItemColors().register((stack, tintIndex) -> tintIndex > 0 ? -1 : MinecraftClient.getInstance().getBlockColors().getColor(((BlockItem) stack.getItem()).getBlock().getDefaultState(), null, null, tintIndex), FRUITING_OAK_LEAVES.get());
}

@SubscribeEvent
public static void registerCreativeModeTabEvents(CreativeModeTabEvent.BuildContents event) {
if(event.getTab() == ItemGroups.NATURAL) {
event.accept(FLOWERING_OAK_LEAVES);
event.getEntries().putAfter(Items.FLOWERING_AZALEA_LEAVES.getDefaultStack(), FLOWERING_OAK_LEAVES.get().asItem().getDefaultStack(), ItemGroup.StackVisibility.PARENT_AND_SEARCH_TABS);
event.accept(FRUITING_OAK_LEAVES);
event.getEntries().putAfter(FLOWERING_OAK_LEAVES.get().asItem().getDefaultStack(), FRUITING_OAK_LEAVES.get().asItem().getDefaultStack(), ItemGroup.StackVisibility.PARENT_AND_SEARCH_TABS);
}
}

}

public Blossom() {
Expand Down
41 changes: 31 additions & 10 deletions src/main/java/dev/yurisuika/blossom/block/FloweringLeavesBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import net.minecraft.block.Fertilizable;
import net.minecraft.block.LeavesBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.Item;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ShearsItem;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
Expand All @@ -17,24 +20,24 @@
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.IntProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.tag.BlockTags;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.event.GameEvent;

import java.util.OptionalInt;
import java.util.Random;

import static dev.yurisuika.blossom.Blossom.*;

Expand All @@ -45,14 +48,15 @@ public class FloweringLeavesBlock extends LeavesBlock implements Fertilizable {

public static final IntProperty DISTANCE = Properties.DISTANCE_1_7;
public static final BooleanProperty PERSISTENT = Properties.PERSISTENT;
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
public static final IntProperty AGE = Properties.AGE_3;
public static final IntProperty RIPENESS = IntProperty.of("ripeness", 0, 7);

public FloweringLeavesBlock(Block shearedBlock, Block pollinatedBlock, Settings settings) {
super(settings);
this.shearedBlock = shearedBlock;
this.pollinatedBlock = pollinatedBlock;
setDefaultState(stateManager.getDefaultState().with(DISTANCE, 1).with(PERSISTENT, false).with(AGE, 0).with(RIPENESS, 0));
setDefaultState(stateManager.getDefaultState().with(DISTANCE, 1).with(PERSISTENT, false).with(WATERLOGGED, false).with(AGE, 0).with(RIPENESS, 0));
}

public VoxelShape getSidesShape(BlockState state, BlockView world, BlockPos pos) {
Expand Down Expand Up @@ -99,22 +103,29 @@ public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random
if (!(Boolean)state.get(PERSISTENT) && state.get(DISTANCE) == 7) {
dropStacks(state, world, pos);
world.removeBlock(pos, false);
} else if (state.get(WATERLOGGED)) {
world.setBlockState(pos, shearedBlock.getDefaultState()
.with(DISTANCE, state.get(DISTANCE))
.with(PERSISTENT, state.get(PERSISTENT))
.with(WATERLOGGED, state.get(WATERLOGGED))
);
} else if (!isMature(state) && world.getBaseLightLevel(pos, 0) >= 9) {
int i = getAge(state);
if (i < getMaxAge()) {
float temperature = world.getBiome(pos).getTemperature();
float downfall = world.getBiome(pos).getDownfall();
float temperature = world.getBiome(pos).value().getTemperature();
float downfall = world.getBiome(pos).value().getDownfall();
temperature += 2;
float f = (downfall * temperature) / 4;
f = ((4 - 1) * f) + 1;
Biome.Precipitation precipitation = world.getBiome(pos).getPrecipitation();
Biome.Precipitation precipitation = world.getBiome(pos).value().getPrecipitation();
if (world.isRaining() && precipitation == Biome.Precipitation.RAIN) {
f = 5.0F;
}
if (random.nextInt((int)(25.0F / f) + 1) == 0) {
world.setBlockState(pos, getDefaultState().with(AGE, i + 1)
.with(DISTANCE, state.get(DISTANCE))
.with(PERSISTENT, state.get(PERSISTENT))
.with(WATERLOGGED, state.get(WATERLOGGED))
.with(RIPENESS, state.get(RIPENESS)), 2);
}
}
Expand All @@ -130,6 +141,7 @@ public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random
world.setBlockState(pos, shearedBlock.getDefaultState()
.with(DISTANCE, state.get(DISTANCE))
.with(PERSISTENT, state.get(PERSISTENT))
.with(WATERLOGGED, state.get(WATERLOGGED))
);
}
if (!isMature(state) && state.get(RIPENESS) > 0) {
Expand All @@ -150,6 +162,7 @@ public void applyGrowth(World world, BlockPos pos, BlockState state) {
world.setBlockState(pos, getDefaultState().with(AGE, i)
.with(DISTANCE, state.get(DISTANCE))
.with(PERSISTENT, state.get(PERSISTENT))
.with(WATERLOGGED, state.get(WATERLOGGED))
.with(RIPENESS, state.get(RIPENESS)), 2);
}

Expand All @@ -162,9 +175,12 @@ public int getOpacity(BlockState state, BlockView world, BlockPos pos) {
}

public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (state.get(WATERLOGGED)) {
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
int i = getDistanceFromLog(neighborState) + 1;
if (i != 1 || state.get(DISTANCE) != i) {
world.getBlockTickScheduler().schedule(pos, this, 1);
world.scheduleBlockTick(pos, this, 1);
}
return state;
}
Expand Down Expand Up @@ -196,6 +212,10 @@ public static OptionalInt getOptionalDistanceFromLog(BlockState state) {
return OptionalInt.empty();
}

public FluidState getFluidState(BlockState state) {
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
}

public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
super.randomDisplayTick(state, world, pos, random);
if (random.nextInt(10) != 0) {
Expand All @@ -211,14 +231,14 @@ public void randomDisplayTick(BlockState state, World world, BlockPos pos, Rando
}

public void appendProperties(Builder<Block, BlockState> builder) {
builder.add(DISTANCE, PERSISTENT, AGE, RIPENESS);
builder.add(DISTANCE, PERSISTENT, WATERLOGGED, AGE, RIPENESS);
}

public BlockState getPlacementState(ItemPlacementContext ctx) {
return updateDistanceFromLogs(getDefaultState().with(PERSISTENT, true).with(AGE, 0).with(RIPENESS, 0), ctx.getWorld(), ctx.getBlockPos());
return updateDistanceFromLogs(getDefaultState().with(PERSISTENT, true).with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER).with(AGE, 0).with(RIPENESS, 0), ctx.getWorld(), ctx.getBlockPos());
}

public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) {
public boolean isFertilizable(WorldView world, BlockPos pos, BlockState state, boolean isClient) {
return !isMature(state);
}

Expand All @@ -245,6 +265,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
world.setBlockState(pos, shearedBlock.getDefaultState()
.with(DISTANCE, state.get(DISTANCE))
.with(PERSISTENT, state.get(PERSISTENT))
.with(WATERLOGGED, state.get(WATERLOGGED))
);
return ActionResult.SUCCESS;
} else {
Expand Down
Loading

0 comments on commit 44c5b29

Please sign in to comment.