Search in sources :

Example 1 with AccessorBlockEntity

use of me.steven.carrier.mixin.AccessorBlockEntity in project Carrier by GabrielOlvH.

the class CarriableSpawner method render.

@Override
@Environment(EnvType.CLIENT)
public void render(@NotNull PlayerEntity player, @NotNull CarrierComponent carrier, @NotNull MatrixStack matrices, @NotNull VertexConsumerProvider vcp, float tickDelta, int light) {
    BlockState blockState = Blocks.SPAWNER.getDefaultState();
    getEntity().readNbt(carrier.getCarryingData().getBlockEntityTag());
    ((AccessorBlockEntity) getEntity()).setWorld(player.world);
    matrices.push();
    matrices.scale(0.6f, 0.6f, 0.6f);
    float yaw = MathHelper.lerpAngleDegrees(tickDelta, player.prevBodyYaw, player.bodyYaw);
    matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(-yaw));
    matrices.translate(-0.5, 0.8, 0.2);
    MinecraftClient.getInstance().getBlockRenderManager().renderBlockAsEntity(blockState, matrices, vcp, light, OverlayTexture.DEFAULT_UV);
    if (MinecraftClient.isFancyGraphicsOrBetter())
        getEntityRenderer().render(getEntity(), tickDelta, matrices, vcp, light, OverlayTexture.DEFAULT_UV);
    matrices.pop();
}
Also used : AccessorBlockEntity(me.steven.carrier.mixin.AccessorBlockEntity) BlockState(net.minecraft.block.BlockState) Environment(net.fabricmc.api.Environment)

Example 2 with AccessorBlockEntity

use of me.steven.carrier.mixin.AccessorBlockEntity in project Carrier by GabrielOlvH.

the class CarriableGeneric method tryPlace.

@Override
@NotNull
public ActionResult tryPlace(@NotNull CarrierComponent carrier, @NotNull World world, @NotNull CarriablePlacementContext ctx) {
    if (world.isClient)
        return ActionResult.PASS;
    CarryingData carrying = carrier.getCarryingData();
    if (carrying == null)
        return ActionResult.PASS;
    BlockPos pos = ctx.getBlockPos();
    BlockState state = carrying.getBlockState() == null ? parent.getDefaultState() : carrying.getBlockState();
    world.setBlockState(pos, state);
    BlockEntity blockEntity = world.getBlockEntity(pos);
    if (blockEntity != null) {
        NbtCompound tag = carrying.getBlockEntityTag();
        ((AccessorBlockEntity) blockEntity).carrier_writeIdentifyingData(tag);
        blockEntity.readNbt(tag);
    }
    carrier.setCarryingData(null);
    world.updateNeighbors(pos, state.getBlock());
    return ActionResult.SUCCESS;
}
Also used : CarryingData(me.steven.carrier.api.CarryingData) AccessorBlockEntity(me.steven.carrier.mixin.AccessorBlockEntity) BlockState(net.minecraft.block.BlockState) NbtCompound(net.minecraft.nbt.NbtCompound) BlockPos(net.minecraft.util.math.BlockPos) AccessorBlockEntity(me.steven.carrier.mixin.AccessorBlockEntity) BlockEntity(net.minecraft.block.entity.BlockEntity) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with AccessorBlockEntity

use of me.steven.carrier.mixin.AccessorBlockEntity in project Carrier by GabrielOlvH.

the class CarriableChest method tryPlace.

@Override
@NotNull
public ActionResult tryPlace(@NotNull CarrierComponent carrier, @NotNull World world, @NotNull CarriablePlacementContext ctx) {
    if (world.isClient)
        return ActionResult.PASS;
    CarryingData carrying = carrier.getCarryingData();
    if (carrying == null)
        return ActionResult.PASS;
    BlockPos pos = ctx.getBlockPos();
    BlockState state = parent.getPlacementState(new ItemPlacementContext(carrier.getOwner(), Hand.MAIN_HAND, ItemStack.EMPTY, new BlockHitResult(new Vec3d(pos.getX(), pos.getY(), pos.getZ()), ctx.getSide(), ctx.getBlockPos(), false)));
    world.setBlockState(pos, state);
    BlockEntity blockEntity = world.getBlockEntity(pos);
    if (blockEntity != null) {
        NbtCompound tag = carrying.getBlockEntityTag();
        ((AccessorBlockEntity) blockEntity).carrier_writeIdentifyingData(tag);
        blockEntity.readNbt(tag);
    }
    carrier.setCarryingData(null);
    return ActionResult.SUCCESS;
}
Also used : CarryingData(me.steven.carrier.api.CarryingData) AccessorBlockEntity(me.steven.carrier.mixin.AccessorBlockEntity) BlockState(net.minecraft.block.BlockState) NbtCompound(net.minecraft.nbt.NbtCompound) BlockPos(net.minecraft.util.math.BlockPos) ItemPlacementContext(net.minecraft.item.ItemPlacementContext) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Vec3d(net.minecraft.util.math.Vec3d) AccessorBlockEntity(me.steven.carrier.mixin.AccessorBlockEntity) BlockEntity(net.minecraft.block.entity.BlockEntity) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with AccessorBlockEntity

use of me.steven.carrier.mixin.AccessorBlockEntity in project Carrier by GabrielOlvH.

the class CarriableEnchantingTable method render.

@Override
@Environment(EnvType.CLIENT)
public void render(@NotNull PlayerEntity player, @NotNull CarrierComponent carrier, @NotNull MatrixStack matrices, @NotNull VertexConsumerProvider vcp, float tickDelta, int light) {
    BlockState blockState = getParent().getDefaultState();
    getEntity().readNbt(carrier.getCarryingData().getBlockEntityTag());
    ((AccessorBlockEntity) getEntity()).setWorld(player.world);
    matrices.push();
    matrices.scale(0.6f, 0.6f, 0.6f);
    float yaw = MathHelper.lerpAngleDegrees(tickDelta, player.prevBodyYaw, player.bodyYaw);
    matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(-yaw));
    matrices.translate(-0.5, 0.8, 0.2);
    MinecraftClient.getInstance().getBlockRenderManager().renderBlockAsEntity(blockState, matrices, vcp, light, OverlayTexture.DEFAULT_UV);
    if (MinecraftClient.isFancyGraphicsOrBetter())
        getEntityRenderer().render(getEntity(), tickDelta, matrices, vcp, light, OverlayTexture.DEFAULT_UV);
    matrices.pop();
}
Also used : AccessorBlockEntity(me.steven.carrier.mixin.AccessorBlockEntity) BlockState(net.minecraft.block.BlockState) Environment(net.fabricmc.api.Environment)

Aggregations

AccessorBlockEntity (me.steven.carrier.mixin.AccessorBlockEntity)4 BlockState (net.minecraft.block.BlockState)4 CarryingData (me.steven.carrier.api.CarryingData)2 Environment (net.fabricmc.api.Environment)2 BlockEntity (net.minecraft.block.entity.BlockEntity)2 NbtCompound (net.minecraft.nbt.NbtCompound)2 BlockPos (net.minecraft.util.math.BlockPos)2 NotNull (org.jetbrains.annotations.NotNull)2 ItemPlacementContext (net.minecraft.item.ItemPlacementContext)1 BlockHitResult (net.minecraft.util.hit.BlockHitResult)1 Vec3d (net.minecraft.util.math.Vec3d)1