Search in sources :

Example 1 with CarryingData

use of me.steven.carrier.api.CarryingData in project Carrier by GabrielOlvH.

the class MixinPlayerRenderer method carrier_renderCarrying.

@Inject(method = "render", at = @At("TAIL"))
private void carrier_renderCarrying(AbstractClientPlayerEntity player, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumerProvider, int light, CallbackInfo ci) {
    CarrierComponent carrier = Carrier.HOLDER.get(player);
    CarryingData carrying = carrier.getCarryingData();
    if (carrying == null)
        return;
    Carriable<?> carriable = CarriableRegistry.INSTANCE.get(carrying.getType());
    if (carriable != null) {
        carriable.render(player, carrier, matrices, vertexConsumerProvider, tickDelta, light);
    }
}
Also used : CarryingData(me.steven.carrier.api.CarryingData) CarrierComponent(me.steven.carrier.api.CarrierComponent) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with CarryingData

use of me.steven.carrier.api.CarryingData in project Carrier by GabrielOlvH.

the class MixinPlayerEntity method a.

@Inject(method = "updateSwimming", at = @At("HEAD"), cancellable = true)
private void a(CallbackInfo ci) {
    CarrierComponent carrier = Carrier.HOLDER.get(this);
    CarryingData carrying = carrier.getCarryingData();
    if (carrying != null) {
        setSwimming(false);
        ci.cancel();
    }
}
Also used : CarryingData(me.steven.carrier.api.CarryingData) CarrierComponent(me.steven.carrier.api.CarrierComponent) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with CarryingData

use of me.steven.carrier.api.CarryingData 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 4 with CarryingData

use of me.steven.carrier.api.CarryingData in project Carrier by GabrielOlvH.

the class ServerWorldTickCallback method onEndTick.

@Override
public void onEndTick(ServerWorld serverWorld) {
    for (ServerPlayerEntity player : serverWorld.getPlayers()) {
        CarrierComponent carrier = Carrier.HOLDER.get(player);
        CarryingData carrying = carrier.getCarryingData();
        if (carrying != null) {
            Config config = Carrier.CONFIG;
            if (config.getSlownessLevel() > 0)
                player.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, 20, config.getSlownessLevel() - 1));
            if (config.getHungerExhaustion() > 0)
                player.getHungerManager().addExhaustion(config.getHungerExhaustion());
        }
    }
}
Also used : CarryingData(me.steven.carrier.api.CarryingData) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) CarrierComponent(me.steven.carrier.api.CarrierComponent)

Example 5 with CarryingData

use of me.steven.carrier.api.CarryingData 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)

Aggregations

CarryingData (me.steven.carrier.api.CarryingData)8 CarrierComponent (me.steven.carrier.api.CarrierComponent)5 Inject (org.spongepowered.asm.mixin.injection.Inject)4 AccessorBlockEntity (me.steven.carrier.mixin.AccessorBlockEntity)3 BlockState (net.minecraft.block.BlockState)3 BlockEntity (net.minecraft.block.entity.BlockEntity)3 NotNull (org.jetbrains.annotations.NotNull)3 NbtCompound (net.minecraft.nbt.NbtCompound)2 BlockPos (net.minecraft.util.math.BlockPos)2 ClientPlayerEntity (net.minecraft.client.network.ClientPlayerEntity)1 StatusEffectInstance (net.minecraft.entity.effect.StatusEffectInstance)1 ItemPlacementContext (net.minecraft.item.ItemPlacementContext)1 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)1 BlockHitResult (net.minecraft.util.hit.BlockHitResult)1 Vec3d (net.minecraft.util.math.Vec3d)1