Search in sources :

Example 1 with IComponent

use of com.lowdragmc.multiblocked.api.tile.IComponent in project Multiblocked by Low-Drag-MC.

the class BlockComponent method setPlacedBy.

@Override
public void setPlacedBy(@Nonnull World level, @Nonnull BlockPos pPos, @Nonnull BlockState pState, @Nullable LivingEntity placer, @Nonnull ItemStack pStack) {
    IComponent component = getComponent(level, pPos);
    if (component != null && placer != null) {
        Vector3d pos = placer.position();
        if (placer instanceof PlayerEntity) {
            component.setOwner(placer.getUUID());
        }
        if (Math.abs(pos.x - (double) ((float) pPos.getX() + 0.5F)) < 2.0D && Math.abs(pos.z - (double) ((float) pPos.getZ() + 0.5F)) < 2.0D) {
            double d0 = pos.y + (double) placer.getEyeHeight();
            if (d0 - (double) pPos.getY() > 2.0D && component.isValidFrontFacing(Direction.UP)) {
                component.setFrontFacing(Direction.UP);
                return;
            }
            if ((double) pPos.getY() - d0 > 0.0D && component.isValidFrontFacing(Direction.DOWN)) {
                component.setFrontFacing(Direction.DOWN);
                return;
            }
        }
        component.setFrontFacing(placer.getDirection().getOpposite());
    }
}
Also used : Vector3d(net.minecraft.util.math.vector.Vector3d) IComponent(com.lowdragmc.multiblocked.api.tile.IComponent) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 2 with IComponent

use of com.lowdragmc.multiblocked.api.tile.IComponent in project Multiblocked by Low-Drag-MC.

the class GeoComponentRenderer method render.

@Override
public void render(TileEntity te, float partialTicks, MatrixStack stack, IRenderTypeBuffer buffer, int combinedLight, int combinedOverlay) {
    if (te instanceof IComponent && ((IComponent) te).getRendererObject() instanceof ComponentFactory) {
        IComponent controller = (IComponent) te;
        ComponentFactory factory = (ComponentFactory) controller.getRendererObject();
        GeoModel model = this.getModel(this.getModelLocation(factory));
        this.setLivingAnimations(factory, this.getUniqueID(factory));
        stack.pushPose();
        stack.translate(0, 0.01f, 0);
        stack.translate(0.5, 0, 0.5);
        switch(controller.getFrontFacing()) {
            case SOUTH:
                stack.mulPose(Vector3f.YP.rotationDegrees(180));
                break;
            case WEST:
                stack.mulPose(Vector3f.YP.rotationDegrees(90));
                break;
            case NORTH:
                stack.mulPose(Vector3f.YP.rotationDegrees(0));
                break;
            case EAST:
                stack.mulPose(Vector3f.YP.rotationDegrees(270));
                break;
            case UP:
                stack.mulPose(Vector3f.XP.rotationDegrees(90));
                break;
            case DOWN:
                stack.mulPose(Vector3f.XN.rotationDegrees(90));
                break;
        }
        render(model, stack, buffer, combinedLight);
        stack.popPose();
    }
}
Also used : IComponent(com.lowdragmc.multiblocked.api.tile.IComponent) AnimatedGeoModel(software.bernie.geckolib3.model.AnimatedGeoModel) GeoModel(software.bernie.geckolib3.geo.render.built.GeoModel)

Example 3 with IComponent

use of com.lowdragmc.multiblocked.api.tile.IComponent in project Multiblocked by Low-Drag-MC.

the class PredicateComponent method buildPredicate.

@Override
public SimplePredicate buildPredicate() {
    predicate = state -> {
        TileEntity tileEntity = state.getTileEntity();
        if (tileEntity instanceof IComponent) {
            return ((IComponent) tileEntity).getDefinition().location.equals(location);
        }
        return false;
    };
    candidates = () -> {
        if (MbdComponents.COMPONENT_BLOCKS_REGISTRY.containsKey(location)) {
            return new BlockInfo[] { new BlockInfo(MbdComponents.COMPONENT_BLOCKS_REGISTRY.get(location).defaultBlockState(), MbdComponents.DEFINITION_REGISTRY.get(location).createNewTileEntity()) };
        } else {
            if (definition == null)
                return new BlockInfo[0];
            if (definition instanceof ControllerDefinition) {
                ControllerTileTesterEntity te = new ControllerTileTesterEntity(ControllerTileTesterEntity.DEFAULT_DEFINITION);
                te.setDefinition((ControllerDefinition) definition);
                return new BlockInfo[] { new BlockInfo(MbdComponents.COMPONENT_BLOCKS_REGISTRY.get(ControllerTileTesterEntity.DEFAULT_DEFINITION.location).defaultBlockState(), te) };
            } else {
                DummyComponentTileEntity te = new DummyComponentTileEntity(MbdComponents.DummyComponentBlock.definition);
                te.setDefinition(definition);
                return new BlockInfo[] { new BlockInfo(MbdComponents.DummyComponentBlock.defaultBlockState(), te) };
            }
        }
    };
    return this;
}
Also used : DummyComponentTileEntity(com.lowdragmc.multiblocked.api.tile.DummyComponentTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ControllerDefinition(com.lowdragmc.multiblocked.api.definition.ControllerDefinition) IComponent(com.lowdragmc.multiblocked.api.tile.IComponent) BlockInfo(com.lowdragmc.lowdraglib.utils.BlockInfo) ControllerTileTesterEntity(com.lowdragmc.multiblocked.api.tile.ControllerTileTesterEntity) DummyComponentTileEntity(com.lowdragmc.multiblocked.api.tile.DummyComponentTileEntity)

Example 4 with IComponent

use of com.lowdragmc.multiblocked.api.tile.IComponent in project Multiblocked by Low-Drag-MC.

the class BlockComponent method getDrops.

@Override
public List<ItemStack> getDrops(BlockState pState, LootContext.Builder pBuilder) {
    LootContext context = pBuilder.withParameter(LootParameters.BLOCK_STATE, pState).create(LootParameterSets.BLOCK);
    Entity entity = context.getParamOrNull(LootParameters.THIS_ENTITY);
    TileEntity tileEntity = context.getParamOrNull(LootParameters.BLOCK_ENTITY);
    if (tileEntity instanceof IComponent && entity instanceof PlayerEntity) {
        NonNullList<ItemStack> drops = NonNullList.create();
        ((IComponent) tileEntity).onDrops(drops, (PlayerEntity) entity);
        return drops;
    }
    return Collections.emptyList();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) TileEntity(net.minecraft.tileentity.TileEntity) LootContext(net.minecraft.loot.LootContext) IComponent(com.lowdragmc.multiblocked.api.tile.IComponent) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

IComponent (com.lowdragmc.multiblocked.api.tile.IComponent)4 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockInfo (com.lowdragmc.lowdraglib.utils.BlockInfo)1 ControllerDefinition (com.lowdragmc.multiblocked.api.definition.ControllerDefinition)1 ControllerTileTesterEntity (com.lowdragmc.multiblocked.api.tile.ControllerTileTesterEntity)1 DummyComponentTileEntity (com.lowdragmc.multiblocked.api.tile.DummyComponentTileEntity)1 Entity (net.minecraft.entity.Entity)1 LivingEntity (net.minecraft.entity.LivingEntity)1 ItemStack (net.minecraft.item.ItemStack)1 LootContext (net.minecraft.loot.LootContext)1 Vector3d (net.minecraft.util.math.vector.Vector3d)1 GeoModel (software.bernie.geckolib3.geo.render.built.GeoModel)1 AnimatedGeoModel (software.bernie.geckolib3.model.AnimatedGeoModel)1