something idk

This commit is contained in:
DrMangoTea
2024-01-27 20:47:04 +01:00
parent 5174a750eb
commit d2d65ee2e5
5 changed files with 797 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
package com.drmangotea.createindustry.blocks.machines.oil_processing.pumpjack.old.crank;
import com.drmangotea.createindustry.registry.TFMGBlockEntities;
import com.drmangotea.createindustry.registry.TFMGShapes;
import com.simibubi.create.content.equipment.wrench.IWrenchable;
import com.simibubi.create.foundation.block.IBE;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
public class PumpjackCrankBlock extends HorizontalDirectionalBlock implements IBE<PumpjackCrankBlockEntity>, IWrenchable {
public PumpjackCrankBlock(Properties p_54120_) {
super(p_54120_);
}
public BlockState getStateForPlacement(BlockPlaceContext p_54779_) {
return this.defaultBlockState().setValue(HorizontalDirectionalBlock.FACING, p_54779_.getHorizontalDirection());
}
@Override
public VoxelShape getShape(BlockState state, BlockGetter p_220053_2_, BlockPos p_220053_3_,
CollisionContext p_220053_4_) {
return TFMGShapes.PUMPJACK_CRANK;
}
@Override
public Class<PumpjackCrankBlockEntity> getBlockEntityClass() {
return PumpjackCrankBlockEntity.class;
}
@Override
public RenderShape getRenderShape(BlockState pState) {
return RenderShape.MODEL;
}
@Override
public BlockEntityType<? extends PumpjackCrankBlockEntity> getBlockEntityType() {
return TFMGBlockEntities.PUMPJACK_CRANK.get();
}
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> p_54794_) {
p_54794_.add(HorizontalDirectionalBlock.FACING);
}
}

View File

@@ -0,0 +1,122 @@
package com.drmangotea.createindustry.blocks.machines.oil_processing.pumpjack.old.crank;
import com.drmangotea.createindustry.blocks.machines.oil_processing.pumpjack.old.hammer_holder.PumpjackHammerHolderBlockEntity;
import com.drmangotea.createindustry.blocks.machines.oil_processing.pumpjack.machine_input.MachineInputBlockEntity;
import com.simibubi.create.content.kinetics.base.KineticBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import static net.minecraft.world.level.block.HorizontalDirectionalBlock.FACING;
public class PumpjackCrankBlockEntity extends KineticBlockEntity {
float targetSpeed;
public float angle=0;
public Direction direction;
public BlockPos hammerPos;
public PumpjackCrankBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
angle=177;
if(direction==Direction.NORTH)
hammerPos =this.getBlockPos().north(2).above();
if(direction==Direction.SOUTH)
hammerPos =this.getBlockPos().south(2).above();
if(direction==Direction.WEST)
hammerPos =this.getBlockPos().west(2).above();
if(direction==Direction.EAST)
hammerPos =this.getBlockPos().east(2).above();
}
@Override
public void write(CompoundTag compound, boolean clientPacket) {
super.write(compound, clientPacket);
if (clientPacket) {
compound.putFloat("Angle", angle);
}
}
@Override
protected void read(CompoundTag compound, boolean clientPacket) {
super.read(compound, clientPacket);
if (clientPacket) {
angle = compound.getFloat("Angle");
}
}
@Override
public void tick() {
super.tick();
direction = this.getBlockState().getValue(HorizontalDirectionalBlock.FACING);
if (!level.isClientSide)
return;
if(direction==Direction.NORTH)
hammerPos =this.getBlockPos().north(2).above();
if(direction==Direction.SOUTH)
hammerPos =this.getBlockPos().south(2).above();
if(direction==Direction.WEST)
hammerPos =this.getBlockPos().west(2).above();
if(direction==Direction.EAST)
hammerPos =this.getBlockPos().east(2).above();
if(!isValid()) {
angle = 177;
return;
}
if(level.getBlockEntity(this.getBlockPos().below())instanceof MachineInputBlockEntity) {
if(((MachineInputBlockEntity)level.getBlockEntity(this.getBlockPos().below())).powerLevel!=0) {
angle += 3;
}else angle=177;
}else
angle=177;
targetSpeed= 10;
angle%=360;
}
public boolean isValid(){
if(hammerPos==null)
return false;
if(!(level.getBlockEntity(hammerPos) instanceof PumpjackHammerHolderBlockEntity))
return false;
if(!(direction==level.getBlockEntity(hammerPos).getBlockState().getValue(HorizontalDirectionalBlock.FACING)))
return false;
return true;
}
/*
private void moveConnectionPos() {
connectionPos = new BlockPos(this.getBlockPos().getX()+0.5f,this.getBlockPos().getY()+0.25f,this.getBlockPos().getZ()+0.5f);
float y=0.8f;
float x=0.8f;
// connectionPos.
}
*/
}

View File

@@ -0,0 +1,180 @@
package com.drmangotea.createindustry.blocks.machines.oil_processing.pumpjack.old.crank;
import com.drmangotea.createindustry.registry.TFMGPartialModels;
import com.jozufozu.flywheel.util.transform.TransformStack;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.simibubi.create.content.kinetics.base.KineticBlockEntity;
import com.simibubi.create.content.kinetics.base.KineticBlockEntityRenderer;
import com.simibubi.create.foundation.render.CachedBufferer;
import com.simibubi.create.foundation.render.SuperByteBuffer;
import com.simibubi.create.foundation.utility.AngleHelper;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.state.BlockState;
import static net.minecraft.world.level.block.HorizontalDirectionalBlock.FACING;
public class PumpjackCrankRenderer extends KineticBlockEntityRenderer {
public PumpjackCrankRenderer(BlockEntityRendererProvider.Context context) {
super(context);
}
@Override
protected void renderSafe(KineticBlockEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light, int overlay) {
renderBlock((PumpjackCrankBlockEntity) te, ms, light,buffer);
// if (Backend.canUseInstancing(te.getLevel()))
// return;
BlockState blockState = te.getBlockState();
PumpjackCrankBlockEntity wte = (PumpjackCrankBlockEntity) te;
float angle = wte.angle * partialTicks;
VertexConsumer vb = buffer.getBuffer(RenderType.solid());
renderCrank(te, ms, light, blockState, angle, vb);
}
private void renderCrank(KineticBlockEntity te, PoseStack ms, int light, BlockState blockState, float angle,
VertexConsumer vb) {
SuperByteBuffer hammer = CachedBufferer.block(blockState);
//kineticRotationTransform(hammer, te, getRotationAxisOf(te), AngleHelper.rad(angle), light);
hammer.renderInto(ms, vb);
}
private void renderBlock(PumpjackCrankBlockEntity be, PoseStack ms, int light,
MultiBufferSource buffer) {
BlockState blockState = be.getBlockState();
VertexConsumer vb = buffer.getBuffer(RenderType.solid());
ms.pushPose();
TransformStack msr = TransformStack.cast(ms);
msr.translate(1 / 2f, 0.5, 1 / 2f);
float dialPivot = 5.75f / 16;
SuperByteBuffer crank = CachedBufferer.partialFacing(TFMGPartialModels.PUMPJACK_CRANK, blockState,blockState.getValue(HorizontalDirectionalBlock.FACING));
CachedBufferer.partialFacing(TFMGPartialModels.PUMPJACK_CRANK_BLOCK, blockState,blockState.getValue(HorizontalDirectionalBlock.FACING))
.translate(-0.5, -0.5, -0.5)
.light(light)
.renderInto(ms,vb);
crank
.translate(-0.5, -0.5, -0.5)
.centre()
.translate(0, -.25, 0)
.rotate(be.getBlockState().getValue(HorizontalDirectionalBlock.FACING).getCounterClockWise(), -AngleHelper.rad(be.angle))
.translate(0, .25, 0)
.unCentre()
.light(light);
crank.renderInto(ms,vb);
if (be.direction == Direction.NORTH){
if(be.isValid()) {
CachedBufferer.partial(TFMGPartialModels.PUMPJACK_CONNECTOR, blockState)
.translate(-0.5, -0.75, -0.5)
.centre()
.rotate(Direction.WEST, -AngleHelper.rad(be.angle))
.unCentre()
.translateY(0.4)
.centre()
.rotate(Direction.WEST, AngleHelper.rad(be.angle))
.unCentre()
.light(light)
.translateY(0.4)
.renderInto(ms, vb);
}
}
if(be.direction == Direction.EAST) {
if(be.isValid()) {
CachedBufferer.partial(TFMGPartialModels.PUMPJACK_CONNECTOR, blockState)
.rotateY(270)
.translate(-0.5, -0.75, -0.5)
.centre()
.rotate(Direction.WEST, -AngleHelper.rad(be.angle))
.unCentre()
.translateY(0.4)
.centre()
.rotate(Direction.WEST, AngleHelper.rad(be.angle))
.unCentre()
.light(light)
.translateY(0.4)
.renderInto(ms, vb);
}
}
if(be.direction == Direction.SOUTH) {
if(be.isValid()) {
CachedBufferer.partial(TFMGPartialModels.PUMPJACK_CONNECTOR, blockState)
.rotateY(180)
.translate(-0.5, -0.75, -0.5)
.centre()
.rotate(Direction.WEST, -AngleHelper.rad(be.angle))
.unCentre()
.translateY(0.4)
.centre()
.rotate(Direction.WEST, AngleHelper.rad(be.angle))
.unCentre()
.light(light)
.translateY(0.4)
.renderInto(ms, vb);
}
}
if(be.direction == Direction.WEST) {
if(be.isValid()) {
CachedBufferer.partial(TFMGPartialModels.PUMPJACK_CONNECTOR, blockState)
.rotateY(90)
.translate(-0.5, -0.75, -0.5)
.centre()
.rotate(Direction.WEST, -AngleHelper.rad(be.angle))
.unCentre()
.translateY(0.4)
.centre()
.rotate(Direction.WEST, AngleHelper.rad(be.angle))
.unCentre()
.light(light)
.translateY(0.4)
.renderInto(ms, vb);
}
}
ms.popPose();
}
@Override
protected BlockState getRenderedBlockState(KineticBlockEntity te) {
return KineticBlockEntityRenderer.shaft(KineticBlockEntityRenderer.getRotationAxisOf(te));
}
}