mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-20 03:44:23 +01:00
Improve the seasons mod integration
This commit is contained in:
parent
fc29057f05
commit
54897e0595
13 changed files with 137 additions and 28 deletions
|
@ -29,6 +29,9 @@ public class UnicopiaMixinPlugin implements IMixinConfigPlugin {
|
||||||
if (mixinClassName.indexOf("trinkets") != -1) {
|
if (mixinClassName.indexOf("trinkets") != -1) {
|
||||||
return FabricLoader.getInstance().isModLoaded("trinkets");
|
return FabricLoader.getInstance().isModLoaded("trinkets");
|
||||||
}
|
}
|
||||||
|
if (mixinClassName.indexOf("seasons") != -1) {
|
||||||
|
return FabricLoader.getInstance().isModLoaded("seasons");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.USounds;
|
import com.minelittlepony.unicopia.USounds;
|
||||||
import com.minelittlepony.unicopia.ability.EarthPonyKickAbility.Buckable;
|
import com.minelittlepony.unicopia.ability.EarthPonyKickAbility.Buckable;
|
||||||
|
import com.minelittlepony.unicopia.seasons.FertilizableUtil;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
|
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
|
||||||
import net.minecraft.block.*;
|
import net.minecraft.block.*;
|
||||||
|
@ -71,40 +72,42 @@ public class FruitBearingBlock extends LeavesBlock implements TintedBlock, Bucka
|
||||||
|
|
||||||
if (world.isDay()) {
|
if (world.isDay()) {
|
||||||
BlockSoundGroup group = getSoundGroup(state);
|
BlockSoundGroup group = getSoundGroup(state);
|
||||||
|
int steps = FertilizableUtil.getGrowthSteps(world, pos, state, random);
|
||||||
if (state.get(STAGE) == Stage.FRUITING) {
|
while (steps-- > 0) {
|
||||||
state = state.cycle(AGE);
|
if (state.get(STAGE) == Stage.FRUITING) {
|
||||||
if (state.get(AGE) > 20) {
|
state = state.cycle(AGE);
|
||||||
|
if (state.get(AGE) > 20) {
|
||||||
|
state = state.with(AGE, 0).cycle(STAGE);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
state = state.with(AGE, 0).cycle(STAGE);
|
state = state.with(AGE, 0).cycle(STAGE);
|
||||||
}
|
}
|
||||||
} else {
|
world.setBlockState(pos, state, Block.NOTIFY_ALL);
|
||||||
state = state.with(AGE, 0).cycle(STAGE);
|
BlockPos fruitPosition = pos.down();
|
||||||
}
|
|
||||||
world.setBlockState(pos, state, Block.NOTIFY_ALL);
|
|
||||||
BlockPos fruitPosition = pos.down();
|
|
||||||
|
|
||||||
Stage stage = state.get(STAGE);
|
Stage stage = state.get(STAGE);
|
||||||
|
|
||||||
if (stage == Stage.FRUITING && isPositionValidForFruit(state, pos)) {
|
if (stage == Stage.FRUITING && isPositionValidForFruit(state, pos)) {
|
||||||
if (world.isAir(fruitPosition)) {
|
if (world.isAir(fruitPosition)) {
|
||||||
world.setBlockState(fruitPosition, fruit.get().getDefaultState(), Block.NOTIFY_ALL);
|
world.setBlockState(fruitPosition, fruit.get().getDefaultState(), Block.NOTIFY_ALL);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
BlockState fruitState = world.getBlockState(fruitPosition);
|
|
||||||
|
|
||||||
if (stage == Stage.WITHERING && fruitState.isOf(fruit.get())) {
|
|
||||||
if (world.random.nextInt(2) == 0) {
|
|
||||||
Block.dropStack(world, fruitPosition, rottenFruitSupplier.get());
|
|
||||||
} else {
|
|
||||||
Block.dropStacks(fruitState, world, fruitPosition, fruitState.hasBlockEntity() ? world.getBlockEntity(fruitPosition) : null, null, ItemStack.EMPTY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (world.removeBlock(fruitPosition, false)) {
|
BlockState fruitState = world.getBlockState(fruitPosition);
|
||||||
world.emitGameEvent(GameEvent.BLOCK_DESTROY, pos, GameEvent.Emitter.of(fruitState));
|
|
||||||
}
|
|
||||||
|
|
||||||
world.playSound(null, pos, USounds.ITEM_APPLE_ROT, SoundCategory.BLOCKS, group.getVolume(), group.getPitch());
|
if (stage == Stage.WITHERING && fruitState.isOf(fruit.get())) {
|
||||||
|
if (world.random.nextInt(2) == 0) {
|
||||||
|
Block.dropStack(world, fruitPosition, rottenFruitSupplier.get());
|
||||||
|
} else {
|
||||||
|
Block.dropStacks(fruitState, world, fruitPosition, fruitState.hasBlockEntity() ? world.getBlockEntity(fruitPosition) : null, null, ItemStack.EMPTY);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (world.removeBlock(fruitPosition, false)) {
|
||||||
|
world.emitGameEvent(GameEvent.BLOCK_DESTROY, pos, GameEvent.Emitter.of(fruitState));
|
||||||
|
}
|
||||||
|
|
||||||
|
world.playSound(null, pos, USounds.ITEM_APPLE_ROT, SoundCategory.BLOCKS, group.getVolume(), group.getPitch());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.minelittlepony.unicopia.mixin.seasons;
|
||||||
|
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Pseudo;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
@Pseudo
|
||||||
|
@Mixin(
|
||||||
|
targets = { "io.github.lucaargolo.seasons.utils.FertilizableUtil" },
|
||||||
|
remap = false
|
||||||
|
)
|
||||||
|
public interface MixinFertilizableUtil {
|
||||||
|
@Invoker("getMultiplier")
|
||||||
|
static float getMultiplier(ServerWorld world, BlockPos pos, BlockState state) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.minelittlepony.unicopia.seasons;
|
||||||
|
|
||||||
|
import com.minelittlepony.unicopia.mixin.seasons.MixinFertilizableUtil;
|
||||||
|
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.random.Random;
|
||||||
|
|
||||||
|
public interface FertilizableUtil {
|
||||||
|
boolean MOD_LOADED = FabricLoader.getInstance().isModLoaded("seasons");
|
||||||
|
|
||||||
|
static float getMultiplier(ServerWorld world, BlockPos pos, BlockState state) {
|
||||||
|
if (MOD_LOADED) {
|
||||||
|
return MixinFertilizableUtil.getMultiplier(world, pos, state);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getGrowthSteps(ServerWorld world, BlockPos pos, BlockState state, Random random) {
|
||||||
|
float multiplier = 1 + FertilizableUtil.getMultiplier(world, pos, state);
|
||||||
|
int steps = 0;
|
||||||
|
|
||||||
|
while (multiplier > 0) {
|
||||||
|
if (multiplier >= random.nextFloat()) {
|
||||||
|
multiplier -= 1;
|
||||||
|
steps++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return steps;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"spring": 0.5,
|
||||||
|
"summer": 0.6,
|
||||||
|
"fall": 1.0,
|
||||||
|
"winter": 0
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"spring": 0.5,
|
||||||
|
"summer": 0.6,
|
||||||
|
"fall": 1.0,
|
||||||
|
"winter": 0
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"spring": 1.0,
|
||||||
|
"summer": 1.6,
|
||||||
|
"fall": 0.5,
|
||||||
|
"winter": 0
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"spring": 1.0,
|
||||||
|
"summer": 1.6,
|
||||||
|
"fall": 0.5,
|
||||||
|
"winter": 0
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"spring": 0.25,
|
||||||
|
"summer": 0.5,
|
||||||
|
"fall": 1.0,
|
||||||
|
"winter": 0.5
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"spring": 0.25,
|
||||||
|
"summer": 0.5,
|
||||||
|
"fall": 1.0,
|
||||||
|
"winter": 0.5
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"spring": 1.0,
|
||||||
|
"summer": 1.0,
|
||||||
|
"fall": 0.6,
|
||||||
|
"winter": 0
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"spring": 1.0,
|
||||||
|
"summer": 1.0,
|
||||||
|
"fall": 0.6,
|
||||||
|
"winter": 0
|
||||||
|
}
|
|
@ -48,7 +48,8 @@
|
||||||
"trinkets.MixinTrinketSurvivalSlot",
|
"trinkets.MixinTrinketSurvivalSlot",
|
||||||
"trinkets.MixinTrinketItem",
|
"trinkets.MixinTrinketItem",
|
||||||
"trinkets.MixinTrinketInventory",
|
"trinkets.MixinTrinketInventory",
|
||||||
"trinkets.MixinScreenHandler"
|
"trinkets.MixinScreenHandler",
|
||||||
|
"seasons.MixinFertilizableUtil"
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
"client.MixinAnimalModel",
|
"client.MixinAnimalModel",
|
||||||
|
|
Loading…
Reference in a new issue