Bonemeal enhancement
This commit is contained in:
parent
6c8c021fb7
commit
5e2335b255
1 changed files with 23 additions and 17 deletions
|
@ -1,7 +1,5 @@
|
||||||
package ru.betterend.mixin.common;
|
package ru.betterend.mixin.common;
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
@ -9,7 +7,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Vec3i;
|
||||||
import net.minecraft.world.InteractionResult;
|
import net.minecraft.world.InteractionResult;
|
||||||
import net.minecraft.world.item.BoneMealItem;
|
import net.minecraft.world.item.BoneMealItem;
|
||||||
import net.minecraft.world.item.context.UseOnContext;
|
import net.minecraft.world.item.context.UseOnContext;
|
||||||
|
@ -23,12 +21,13 @@ import ru.betterend.registry.EndBlocks;
|
||||||
import ru.betterend.registry.EndTags;
|
import ru.betterend.registry.EndTags;
|
||||||
import ru.betterend.util.BlocksHelper;
|
import ru.betterend.util.BlocksHelper;
|
||||||
import ru.betterend.util.BonemealUtil;
|
import ru.betterend.util.BonemealUtil;
|
||||||
|
import ru.betterend.util.MHelper;
|
||||||
import ru.betterend.world.biome.EndBiome;
|
import ru.betterend.world.biome.EndBiome;
|
||||||
|
|
||||||
@Mixin(BoneMealItem.class)
|
@Mixin(BoneMealItem.class)
|
||||||
public class BoneMealItemMixin {
|
public class BoneMealItemMixin {
|
||||||
private static final Direction[] DIR = BlocksHelper.makeHorizontal();
|
|
||||||
private static final MutableBlockPos POS = new MutableBlockPos();
|
private static final MutableBlockPos POS = new MutableBlockPos();
|
||||||
|
private static final Vec3i[] DIR;
|
||||||
|
|
||||||
@Inject(method = "useOn", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "useOn", at = @At("HEAD"), cancellable = true)
|
||||||
private void be_onUse(UseOnContext context, CallbackInfoReturnable<InteractionResult> info) {
|
private void be_onUse(UseOnContext context, CallbackInfoReturnable<InteractionResult> info) {
|
||||||
|
@ -149,22 +148,29 @@ public class BoneMealItemMixin {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void be_shuffle(Random random) {
|
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
int j = random.nextInt(4);
|
|
||||||
Direction d = DIR[i];
|
|
||||||
DIR[i] = DIR[j];
|
|
||||||
DIR[j] = d;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private BlockState be_getNylium(Level world, BlockPos pos) {
|
private BlockState be_getNylium(Level world, BlockPos pos) {
|
||||||
be_shuffle(world.random);
|
MHelper.shuffle(DIR, world.getRandom());
|
||||||
for (Direction dir : DIR) {
|
for (Vec3i dir : DIR) {
|
||||||
BlockState state = world.getBlockState(pos.relative(dir));
|
BlockPos p = pos.offset(dir);
|
||||||
if (BlocksHelper.isEndNylium(state))
|
BlockState state = world.getBlockState(p);
|
||||||
|
if (BlocksHelper.isEndNylium(state) && !world.getBlockState(p.above()).is(EndTags.END_GROUND)) {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
int index = 0;
|
||||||
|
DIR = new Vec3i[3 * 3 * 3 - 1];
|
||||||
|
for (int x = -1; x <= 1; x++) {
|
||||||
|
for (int y = -1; y <= 1; y++) {
|
||||||
|
for (int z = -1; z <= 1; z++) {
|
||||||
|
if (x != 0 || y != 0 || z != 0) {
|
||||||
|
DIR[index++] = new Vec3i(x, y, z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue