resolve fabric todos
This commit is contained in:
parent
59378e8031
commit
4e6d47de41
6 changed files with 106 additions and 17 deletions
|
@ -1,15 +1,14 @@
|
||||||
package at.petrak.hexcasting.common.blocks;
|
package at.petrak.hexcasting.common.blocks;
|
||||||
|
|
||||||
import at.petrak.hexcasting.annotations.SoftImplement;
|
|
||||||
import at.petrak.hexcasting.api.misc.FrozenColorizer;
|
import at.petrak.hexcasting.api.misc.FrozenColorizer;
|
||||||
import at.petrak.hexcasting.common.blocks.entity.BlockEntityConjured;
|
import at.petrak.hexcasting.common.blocks.entity.BlockEntityConjured;
|
||||||
|
import at.petrak.hexcasting.xplat.IForgeLikeBlock;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.sounds.SoundEvents;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.level.BlockGetter;
|
import net.minecraft.world.level.BlockGetter;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.LevelAccessor;
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
|
@ -20,14 +19,13 @@ import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.phys.HitResult;
|
|
||||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||||
import net.minecraft.world.phys.shapes.Shapes;
|
import net.minecraft.world.phys.shapes.Shapes;
|
||||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class BlockConjured extends Block implements EntityBlock {
|
public class BlockConjured extends Block implements EntityBlock, IForgeLikeBlock {
|
||||||
|
|
||||||
public BlockConjured(Properties properties) {
|
public BlockConjured(Properties properties) {
|
||||||
super(properties);
|
super(properties);
|
||||||
|
@ -112,9 +110,7 @@ public class BlockConjured extends Block implements EntityBlock {
|
||||||
// NO-OP
|
// NO-OP
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO figure out how to impl these in fabric
|
@Override
|
||||||
|
|
||||||
@SoftImplement("forge")
|
|
||||||
public boolean addLandingEffects(BlockState state1, ServerLevel worldserver, BlockPos pos, BlockState state2,
|
public boolean addLandingEffects(BlockState state1, ServerLevel worldserver, BlockPos pos, BlockState state2,
|
||||||
LivingEntity entity, int numberOfParticles) {
|
LivingEntity entity, int numberOfParticles) {
|
||||||
BlockEntity tile = worldserver.getBlockEntity(pos);
|
BlockEntity tile = worldserver.getBlockEntity(pos);
|
||||||
|
@ -123,11 +119,5 @@ public class BlockConjured extends Block implements EntityBlock {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SoftImplement("forge")
|
|
||||||
public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGetter level, BlockPos pos,
|
|
||||||
Player player) {
|
|
||||||
return ItemStack.EMPTY;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package at.petrak.hexcasting.common.blocks.akashic;
|
package at.petrak.hexcasting.common.blocks.akashic;
|
||||||
|
|
||||||
import at.petrak.hexcasting.annotations.SoftImplement;
|
|
||||||
import at.petrak.hexcasting.api.spell.DatumType;
|
import at.petrak.hexcasting.api.spell.DatumType;
|
||||||
import at.petrak.hexcasting.api.spell.SpellDatum;
|
import at.petrak.hexcasting.api.spell.SpellDatum;
|
||||||
import at.petrak.hexcasting.common.items.ItemScroll;
|
import at.petrak.hexcasting.common.items.ItemScroll;
|
||||||
import at.petrak.hexcasting.common.lib.HexBlocks;
|
import at.petrak.hexcasting.common.lib.HexBlocks;
|
||||||
import at.petrak.hexcasting.common.lib.HexSounds;
|
import at.petrak.hexcasting.common.lib.HexSounds;
|
||||||
|
import at.petrak.hexcasting.xplat.IForgeLikeBlock;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
|
@ -28,7 +28,7 @@ import net.minecraft.world.level.block.state.properties.EnumProperty;
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class BlockAkashicBookshelf extends BlockAkashicFloodfiller implements EntityBlock {
|
public class BlockAkashicBookshelf extends BlockAkashicFloodfiller implements EntityBlock, IForgeLikeBlock {
|
||||||
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
|
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
|
||||||
public static final EnumProperty<DatumType> DATUM_TYPE = EnumProperty.create("datum_type", DatumType.class);
|
public static final EnumProperty<DatumType> DATUM_TYPE = EnumProperty.create("datum_type", DatumType.class);
|
||||||
|
|
||||||
|
@ -115,8 +115,7 @@ public class BlockAkashicBookshelf extends BlockAkashicFloodfiller implements En
|
||||||
return this.defaultBlockState().setValue(FACING, ctx.getHorizontalDirection().getOpposite());
|
return this.defaultBlockState().setValue(FACING, ctx.getHorizontalDirection().getOpposite());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: fabric
|
@Override
|
||||||
@SoftImplement("Forge")
|
|
||||||
public float getEnchantPowerBonus(BlockState state, LevelReader level, BlockPos pos) {
|
public float getEnchantPowerBonus(BlockState state, LevelReader level, BlockPos pos) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package at.petrak.hexcasting.xplat;
|
||||||
|
|
||||||
|
import at.petrak.hexcasting.annotations.SoftImplement;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
import net.minecraft.world.level.LevelReader;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An interface that mimics some methods of IForgeBlock.
|
||||||
|
* Fabric implementation will use mixins to achieve the same effect.
|
||||||
|
*/
|
||||||
|
public interface IForgeLikeBlock {
|
||||||
|
@SoftImplement("forge")
|
||||||
|
default boolean addLandingEffects(BlockState state1, ServerLevel level, BlockPos pos, BlockState state2, LivingEntity entity, int numberOfParticles) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On Fabric, this method's return value doesn't matter - it's only checked for whether it's greater than 0.
|
||||||
|
* Implementing boosts the way Forge does would... not be worth the effort.
|
||||||
|
*/
|
||||||
|
@SoftImplement("forge")
|
||||||
|
default float getEnchantPowerBonus(BlockState state, LevelReader level, BlockPos pos) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package at.petrak.hexcasting.fabric.mixin;
|
||||||
|
|
||||||
|
import at.petrak.hexcasting.xplat.IForgeLikeBlock;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.EnchantmentTableBlock;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@Mixin(EnchantmentTableBlock.class)
|
||||||
|
public class FabricEnchantmentTableBlockMixin {
|
||||||
|
@Inject(method = "isValidBookShelf", at = @At("HEAD"), cancellable = true)
|
||||||
|
private static void treatAsBookshelf(Level level, BlockPos blockPos, BlockPos blockPos2, CallbackInfoReturnable<Boolean> cir) {
|
||||||
|
BlockState state = level.getBlockState(blockPos.offset(blockPos2));
|
||||||
|
if (state.getBlock() instanceof IForgeLikeBlock forgeLike) {
|
||||||
|
boolean emptyBetween = level.isEmptyBlock(blockPos.offset(blockPos2.getX() / 2, blockPos2.getY(), blockPos2.getZ() / 2));
|
||||||
|
cir.setReturnValue(emptyBetween && forgeLike.getEnchantPowerBonus(state, level, blockPos) > 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package at.petrak.hexcasting.fabric.mixin;
|
||||||
|
|
||||||
|
import at.petrak.hexcasting.xplat.IForgeLikeBlock;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.util.Mth;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
import net.minecraft.world.level.block.Blocks;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||||
|
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||||
|
|
||||||
|
@Mixin(LivingEntity.class)
|
||||||
|
public class FabricLivingEntityMixin {
|
||||||
|
@Unique
|
||||||
|
private BlockState hex$cachedParticleState;
|
||||||
|
|
||||||
|
@ModifyVariable(method = "checkFallDamage", at = @At(value = "LOAD", ordinal = 0), argsOnly = true)
|
||||||
|
private BlockState overwrite(BlockState state, double d, boolean bl, BlockState _ignored, BlockPos pos) {
|
||||||
|
LivingEntity entity = (LivingEntity) (Object) this;
|
||||||
|
|
||||||
|
if (state.getBlock() instanceof IForgeLikeBlock forgeLike) {
|
||||||
|
float dist = (float) Mth.ceil(entity.fallDistance - 3.0F);
|
||||||
|
double e = Math.min(0.2F + dist / 15.0F, 2.5D);
|
||||||
|
int i = (int)(150.0D * e);
|
||||||
|
if (forgeLike.addLandingEffects(state, (ServerLevel) entity.level, pos, state, entity, i)) {
|
||||||
|
hex$cachedParticleState = state;
|
||||||
|
return Blocks.AIR.defaultBlockState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ModifyArg(method = "checkFallDamage", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;checkFallDamage(DZLnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/BlockPos;)V"))
|
||||||
|
private BlockState restore(BlockState state) {
|
||||||
|
if (hex$cachedParticleState != null) {
|
||||||
|
BlockState cached = hex$cachedParticleState;
|
||||||
|
hex$cachedParticleState = null;
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,7 +7,9 @@
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"FabricAxeItemMixin",
|
"FabricAxeItemMixin",
|
||||||
"FabricBlockBehaviorMixin",
|
"FabricBlockBehaviorMixin",
|
||||||
|
"FabricEnchantmentTableBlockMixin",
|
||||||
"FabricItemEntityMixin",
|
"FabricItemEntityMixin",
|
||||||
|
"FabricLivingEntityMixin",
|
||||||
"FabricVillagerTurnIntoWitchMixin"
|
"FabricVillagerTurnIntoWitchMixin"
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
|
|
Loading…
Reference in a new issue