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());
}
}
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();
}
}
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;
}
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();
}
Aggregations