Skip to content

Commit

Permalink
Fixed wings
Browse files Browse the repository at this point in the history
  • Loading branch information
Eriksonnaren committed Apr 1, 2022
1 parent 23cb058 commit 811dfad
Show file tree
Hide file tree
Showing 19 changed files with 825 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"variants": {
"facing=north,lit=false": {
"model": "createaeronautics:block/stirling_engine/block"
},
"facing=south,lit=false": {
"model": "createaeronautics:block/stirling_engine/block",
"y": 180
},
"facing=west,lit=false": {
"model": "createaeronautics:block/stirling_engine/block",
"y": 270
},
"facing=east,lit=false": {
"model": "createaeronautics:block/stirling_engine/block",
"y": 90
},
"facing=north,lit=true": {
"model": "createaeronautics:block/stirling_engine/block_lit"
},
"facing=south,lit=true": {
"model": "createaeronautics:block/stirling_engine/block_lit",
"y": 180
},
"facing=west,lit=true": {
"model": "createaeronautics:block/stirling_engine/block_lit",
"y": 270
},
"facing=east,lit=true": {
"model": "createaeronautics:block/stirling_engine/block_lit",
"y": 90
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "createaeronautics:block/stirling_engine/item"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"type": "minecraft:block",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:item",
"name": "createaeronautics:stirling_engine"
}
],
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected void createBlockStateDefinition(StateContainer.Builder<Block, BlockSta
public void onRemove(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
if (state.hasTileEntity() && state.getBlock() != newState.getBlock()) {
StirlingEngineTileEntity te = (StirlingEngineTileEntity) worldIn.getBlockEntity(pos);
if (!te.currentStack.isEmpty())
if (te !=null&&!te.currentStack.isEmpty())
InventoryHelper.dropItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), te.currentStack);
worldIn.removeBlockEntity(pos);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.eriksonn.createaeronautics.connected;


import com.eriksonn.createaeronautics.CreateAeronautics;
import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry;
import com.simibubi.create.foundation.block.render.SpriteShifter;
import net.minecraft.util.ResourceLocation;

public class CTSpriteShifter extends SpriteShifter {
public static CTSpriteShiftEntry getCT(com.simibubi.create.foundation.block.connected.CTSpriteShifter.CTType type, ResourceLocation blockTexture, ResourceLocation connectedTexture) {
String key = type.name() + ":" + blockTexture + "->" + connectedTexture;
if (ENTRY_CACHE.containsKey(key))
return (CTSpriteShiftEntry) ENTRY_CACHE.get(key);

CTSpriteShiftEntry entry = create(type);
entry.set(blockTexture, connectedTexture);
ENTRY_CACHE.put(key, entry);
return entry;
}

public static CTSpriteShiftEntry getCT(com.simibubi.create.foundation.block.connected.CTSpriteShifter.CTType type, String blockTextureName, String connectedTextureName) {
return getCT(type, CreateAeronautics.asResource("block/" + blockTextureName), CreateAeronautics.asResource("block/" + connectedTextureName + "_connected"));
}

public static CTSpriteShiftEntry getCT(com.simibubi.create.foundation.block.connected.CTSpriteShifter.CTType type, String blockTextureName) {
return getCT(type, blockTextureName, blockTextureName);
}

private static CTSpriteShiftEntry create(com.simibubi.create.foundation.block.connected.CTSpriteShifter.CTType type) {
switch (type) {
case HORIZONTAL:
return new CTSpriteShiftEntry.Horizontal();
case OMNIDIRECTIONAL:
return new CTSpriteShiftEntry.Omnidirectional();
case VERTICAL:
return new CTSpriteShiftEntry.Vertical();
case CROSS:
return new CTSpriteShiftEntry.Cross();
default:
return null;
}
}

public enum CTType {
OMNIDIRECTIONAL, HORIZONTAL, VERTICAL, CROSS;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class AirshipContraptionEntity extends AbstractContraptionEntity {
public AirshipContraption airshipContraption;
public int plotId = 0;
public SimulatedContraptionRigidbody simulatedRigidbody;
public Map<BlockPos, BlockState> sails;

public Map<UUID, ControlledContraptionEntity> subContraptions = new HashMap<>();
public Vector3d centerOfMassOffset = Vector3d.ZERO;
public static final DataParameter<CompoundNBT> physicsDataAccessor = EntityDataManager.defineId(AirshipContraptionEntity.class, DataSerializers.COMPOUND_TAG);
Expand All @@ -85,7 +85,6 @@ protected void defineSynchedData() {

public AirshipContraptionEntity(EntityType<?> type, World world) {
super(type, world);
sails = new HashMap<>();
simulatedRigidbody = new SimulatedContraptionRigidbody(this);
System.out.println("New airship entity");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

import com.simibubi.create.content.contraptions.components.structureMovement.ControlledContraptionEntity;
import com.simibubi.create.content.contraptions.components.structureMovement.StructureTransform;
import net.minecraft.util.math.BlockPos;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(ControlledContraptionEntity.class)
public interface ControlledContraptionEntityMixin {

@Invoker(value = "makeStructureTransform", remap = false)
public StructureTransform invokeMakeStructureTransform();

@Accessor(remap = false)
BlockPos getControllerPos();
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package com.eriksonn.createaeronautics.physics;

import com.simibubi.create.content.contraptions.components.structureMovement.Contraption;
import com.simibubi.create.content.contraptions.components.structureMovement.bearing.SailBlock;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.gen.feature.template.Template;

import java.util.HashMap;
import java.util.Map;

public abstract class AbstractContraptionRigidbody implements IRigidbody{

public Vector3d localCenterOfMass=Vector3d.ZERO;
public double[][] localInertiaTensor=new double[3][3];
public double localMass;
public Map<BlockPos, BlockState> sails = new HashMap<>();
public void generateMassDependentParameters(Contraption contraption,Vector3d offset)
{
localMass=0;
Expand Down Expand Up @@ -43,6 +47,15 @@ public void generateMassDependentParameters(Contraption contraption,Vector3d off
}
}
}
public void findSails(Contraption contraption)
{
sails.clear();
for (Map.Entry<BlockPos, Template.BlockInfo> entry : contraption.getBlocks().entrySet()) {
if(entry.getValue().state.getBlock() instanceof SailBlock) {
sails.put(entry.getKey(),entry.getValue().state);
}
}
}
public double getLocalMass() { return localMass; }
public Vector3d getLocalCenterOfMass(){ return localCenterOfMass; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.eriksonn.createaeronautics.blocks.propeller_bearing.PropellerBearingTileEntity;
import com.eriksonn.createaeronautics.index.CABlocks;
import com.eriksonn.createaeronautics.index.CATileEntities;
import com.eriksonn.createaeronautics.mixins.ControlledContraptionEntityMixin;
import com.eriksonn.createaeronautics.particle.PropellerAirParticleData;
import com.simibubi.create.AllTileEntities;
import com.simibubi.create.content.contraptions.components.fan.EncasedFanTileEntity;
Expand Down Expand Up @@ -70,7 +71,7 @@ public class SimulatedContraptionRigidbody extends AbstractContraptionRigidbody
public SimulatedContraptionRigidbody(AirshipContraptionEntity entity)
{
orientation=Quaternion.ONE.copy();
//orientation=new Quaternion(1,0,0,1);
//orientation=new Quaternion(0,1,0,1);
//orientation.normalize();

this.entity=entity;
Expand All @@ -87,9 +88,16 @@ public void tryInit()
{
if(!isInitialized) {
contraption=entity.airshipContraption;
//updateCenterOfMass();

generateMassDependentParameters(contraption,Vector3d.ZERO);
mergeMassFromSubContraptions();

updateLevititeBuoyancy();
isInitialized=true;
updateRotation();
//applyImpulse(new Vector3d(0,0,1),new Vector3d(0,7,0));
Vector3d V = getVelocityAtPoint(new Vector3d(0,0,1));
Vector3d V2 = V.cross(V);
}
}
public void tick()
Expand All @@ -110,21 +118,31 @@ public void tick()



//updateWings();
updateWings();
//updateInertia();
updateTileEntityInteractions();
centerOfMass=Vector3d.ZERO;
//centerOfMass=Vector3d.ZERO;
totalAccumulatedBuoyancy =0;

totalAccumulatedBuoyancy += levititeBuoyancyController.apply(orientation,entity.position());
updateRotation();

globalForce=globalForce.add(0,-totalAccumulatedBuoyancy,0);
//globalForce=globalForce.add(0,-PhysicsUtils.gravity*mass,0);

momentum = momentum.add(rotateQuat(localForce.scale(PhysicsUtils.deltaTime),orientation)).add(globalForce.scale(PhysicsUtils.deltaTime));
globalForce = Vector3d.ZERO;
localForce = Vector3d.ZERO;

if(entity.position().y<75)
{
entity.move(0,75-entity.position().y,0);
if(momentum.y<0)
{
momentum=momentum.multiply(1,-0.5,1);
}
}

momentum=momentum.scale(0.995);
globalVelocity=momentum.scale(1.0/mass);
localVelocity = rotateQuatReverse(globalVelocity,orientation);
Expand Down Expand Up @@ -514,37 +532,49 @@ Vector3d multiplyMatrixArray(double[][] M,Vector3d v)
}
void updateWings()
{
for (Map.Entry<BlockPos, BlockState> entry : entity.sails.entrySet())
findSails(this.contraption);

for (Map.Entry<BlockPos, BlockState> entry : sails.entrySet())
{
Vector3d pos = getLocalCoordinate(entry.getKey());
Vector3d vel = getLocalVelocityAtPosition(pos);
Vector3d normal = getFacingVector(entry.getValue());
Vector3d force = normal.scale(-0.8f*normal.dot(vel));
Vector3d force = normal.scale(-3.0f*normal.dot(vel));
addForce(force,pos);
}
for (Map.Entry<UUID, ControlledContraptionEntity> contraptionEntityEntry : entity.subContraptions.entrySet())

for (Map.Entry<UUID, SubcontraptionRigidbody> entry : subcontraptionRigidbodyMap.entrySet())
{
// TODO: make propellers not provide lift
if(contraptionEntityEntry.getValue() != null)
AbstractContraptionEntity entity = entry.getValue().entity;
Contraption subContraption = entity.getContraption();

entry.getValue().findSails(subContraption);

if(entity instanceof ControlledContraptionEntity) {
ControlledContraptionEntity controlledEntity = (ControlledContraptionEntity)entity;
TileEntity te = entity.level.getBlockEntity(((ControlledContraptionEntityMixin)controlledEntity).getControllerPos());
if (te instanceof PropellerBearingTileEntity) {
continue;
}
}

for (Map.Entry<BlockPos, Template.BlockInfo> blockStateEntry : subContraption.getBlocks().entrySet())
{
Contraption subContraption = contraptionEntityEntry.getValue().getContraption();
if(blockStateEntry.getValue().state.getBlock() instanceof SailBlock) {

for (Map.Entry<BlockPos, Template.BlockInfo> blockStateEntry : subContraption.getBlocks().entrySet())
{
if(blockStateEntry.getValue().state.getBlock() instanceof SailBlock) {
Vector3d pos = VecHelper.getCenterOf(blockStateEntry.getKey());
pos=entry.getValue().toParent(pos);

Vector3d pos = contraptionEntityEntry.getValue().applyRotation(VecHelper.getCenterOf(blockStateEntry.getKey()),0);
pos.subtract(centerOfMass);
Vector3d vel = getLocalVelocityAtPosition(pos);
Vector3d normal = getFacingVector(blockStateEntry.getValue().state);
normal = contraptionEntityEntry.getValue().applyRotation(normal,0);
Vector3d force = normal.scale(-0.8f*normal.dot(vel));
addForce(force,pos);
Vector3d vel = getLocalVelocityAtPosition(pos);
Vector3d normal = getFacingVector(blockStateEntry.getValue().state);
normal = entity.applyRotation(normal,1);
Vector3d force = normal.scale(-3.0f*normal.dot(vel));
addForce(force,pos);

}
}
}
}

}
public Vector3d getPlotOffset()
{
Expand Down Expand Up @@ -649,6 +679,16 @@ Vector3d getLocalVelocityAtPosition(Vector3d pos)
{
return localVelocity.add(pos.cross(angularVelocity));
}
public void applyImpulse(Vector3d pos, Vector3d impulse) {
momentum = momentum.add(impulse);
globalVelocity = momentum.scale(1.0 / getMass());

// if(Math.abs(impulse.scale(1.0 / getMass()).lengthSqr()) < 0.05) return;

Vector3d additionalAngularMomentum = rotateInverse(impulse).cross(pos);
angularMomentum = angularMomentum.add(additionalAngularMomentum);
updateRotation();
}
Vector3d getForcePropellerBearing(BlockPos pos,PropellerBearingTileEntity te)
{
if(!te.isRunning())
Expand Down
Loading

0 comments on commit 811dfad

Please sign in to comment.