Jump to content

Recommended Posts

Posted

I want to make an API that allows forces to be sent to a rigid-body from inside a Block or TileEntity. I'm thinking of having 2 types of forces to add, a one-off that will apply that force for 1 tick, and a passive one that adds the force to a HashMap containing the blockPos and the corresponding force. This is how I've been adding forces at the moment.

 

public void calculateForces(){
	torque.zero();
	translationForces.multiply(.;
	for(BlockPos pos:parent.blockPositions){
		if(pos!=null&&weightAtPos.containsKey(pos)){
			Vector inBodyWO = BigBastardMath.getBodyPosWithOrientation(pos, centerOfMass, parent.rotationTransform);
			Vector forceActing = new Vector(0.0D,-9.8D*weightAtPos.get(pos),0.0D);
			double distance = inBodyWO.length();
			if(parent.region.getBlockState(pos).getBlock().equals(Blocks.wool)){
				forceActing.add(new Vector(0.0D,200D,0.0D));
			}
			if(parent.region.getBlockState(pos).getBlock().equals(Blocks.iron_block)){
				Vector newForce = new Vector(200.0D,0.0D,0.0D);
				Rotations.applyTransform(parent.rotationTransform,newForce);
				forceActing.add(newForce);
			}
			torque.add(inBodyWO.cross(forceActing));
			translationForces.add(forceActing);
		}
	}

 

By default the forceActing vector is just the mass of the block times the gravity on the ship. The vector inBodyWO is the block's position with respect to the center of mass and the ship's orientation. The only thing adding forces here is the 2 if-statements checking if the block is Wool or Iron, and there it adds a "passive" force. The wool block doing an up-force, and the iron block doing a force on its East-Side. I'd record something but Im programming on a chromebook at the moment.

 

Anyway you guys are better programmers than me, how should I structure an API that allows blocks/tileEntities to add forces to the rigid-body so that other mods could program engines and crap (Like an ic2 engine that powers your airship)

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

Posted

Typically people don't set out to 'make an API' for something they don't themselves intend to do. If you're not making an engine or some such that will need this API, chances are your API will not be very good for the simple fact that you aren't actually using it, so there will be lots of cases that you won't think of and it may not even provided the functionality modders will ultimately need.

 

Also, consider that any mod already containing engines and such things are 99.9999% likely to continue doing it the way they always have been, even if your API turned out to be the best thing since canned meat. You should really think about who your target audience is, if any, for this API, and if it is even needed. Is there a compatibility problem you are trying to solve? How many 'standards' have already been developed, and what is their current usage? Do you think we need another one?

 

I'm not trying to be a downer here, just posing some realistic questions you should ask yourself before undertaking what could prove to be a complete waste of your time, unless of course you are doing it to learn, in which case go right ahead.

 

If you do go ahead with it, stuff like this:

if(parent.region.getBlockState(pos).getBlock().equals(Blocks.iron_block)){

is going to be a big problem. Sure, that's for a vanilla block, but wherever you can, you want to use interfaces. If you can't for whatever reason (such as for vanilla blocks), then you need to code in a way that lets you leave the public-facing API the same while still being able to tweak the internals.

 

So, for example, the two if statements inside your code block there that check the blockstate, I would rewrite to be something like this:

Block block = parent.region.getBlockState(pos).getBlock();
Vector newForce = null;
if (block instanceof IForceBlock) {
  newForce = ((IForceBlock) block).getForce(world, state, pos); // and whatever other parameters you need
} else {
  newForce = getForceForVanillaBlock(state, pos); // and whatever other parameters you need
}
if (newForce != null) { // assuming both are handled the same
  // apply rotation, add force to collection, etc.
}

`getForceForVanillaBlock` could simply return a value from an immutable hashmap containing Block:Vector pairs that you populate at run-time; you could even allow mods to add their own blocks to this map via inter-mod messages, if you want.

 

There are a lot of ways you can go about it, but always prefer abstraction and interfaces to hard-coding specific values.

Posted

Cool, I think I've covered it with 2 small interfaces. I know more API's are a pain so I've made it as small and simple as possible. This takes literally 5 minutes to add to anything.

 

package FlyingFortress.API;

import net.minecraft.block.state.IBlockState;
import net.minecraft.util.BlockPos;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;

//An interface a block can implement this to add its own forces to the Rigid-Bodies
public interface IForceBlock {

//Note that this Vector should inculde the effects of gravity
public Vec3 getForceActing(World world, IBlockState state,BlockPos pos);

//false for things that aren't directional like Balloons, true for things that are like Engines
public boolean isForceInLocal(World world,IBlockState state,BlockPos pos);

}

 

package FlyingFortress.API;

import net.minecraft.util.Vec3;
import net.minecraft.world.World;

public interface IForceEntity {

public boolean isForceInLocal(World shipWorld,Vec3 localPosInShipWorld);

//Called every tick when an entity is "inside" of a Ship
public Vec3 getForceActingIn(World shipWorld,Vec3 localPosInShipWorld);

}

 

1 last question, how do I setup the classpath so that when other mods use these classes only 1 instance of these classes are loaded at runtime?

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • 🔻 SERVER IP: 90.146.113.53 Watch the Server-Trailer now!     ArenaSMP is a brand new minecraft survival server combining the vanilla survival experience with the following exciting enhancements: In the PVE Arena, combat skeletons whom will when defeated by the player reward them with money which can be spent to purchase ranks with cool permissions such as disguising as a mob, setting multiple homes, accessing the enderchest by command and many more! To enhance your gameplay there are few tough named skeletons with a minor percent chance to drop highly enchanted tools when defeated! But that isn't all, theres a whole world dedicated to bring you the most exciting minecraft experience you've ever had. The treasurehunt world, a place made of massive scary abandoned mineshafts and underground ruins, is populated by very though skeletons and zombies guarding the most powerful treasures including armor and weapons with unique enchantments that will change the way you progress in survival forever! Some secret places hiding the most powerful treasures are difficult to find, only those who look behind every path and corner where nobody else would look might get the chance becomming an undefeatable GOD. The Enderdragon is yet alive, will you be the one to hunt it down first? Will you become the next GOD in arenasmp? Join now! As a bonus, the first 5 players joining will instantly recive a free rankup! What does ArenaSMP offer exactly? • Vanilla like Survival experience, Nether and End World • Hub with portals to various locations • PVE Arena • Treasurehunt World with many secrets • Powerful Hidden Gear • Ranks to be purchased with ingame-money • Landprotection for all players • Players with any minecraft version can join • Shields are disabled, we use the 1.8 combatsystem including sword blocking • Change your skin with the /skins command • Creepers don't destroy blocks and Phantoms are disabled • Defeated skeletons reward the player with ingame-money • Anticheat enabled • Survival World will never reset • Automatic Daily Server Backups Watch the Server-Trailer now! https://www.youtube.com/watch?v=xl5GfTizasI 🔻 SERVER IP: 90.146.113.53
    • I'm simply trying to start up a forever world with mods, but I don't understand what this crash report means. Can I get someone to diagnose the problem? https://pastebin.com/yRsq3C2A
    • I've successfully setup multi mc with two instances and i've split the audio going into my headset and another going into my quest, it works perfectly although whenever i tab out into instance 1 (pc) and go into instance 2 (vr) i can hear the pc audio still and i can also hear the vr audio but only when i am focused on the window it instantly goes mute when i lose focus im not sure what to do i've tried messing around with the sound system classes in my client build but i cant get my gradle build to work i cant find a simple tweak for this version that solves this issue i just need instance 2 to constantly play audio regardless if im tabbed in or not
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.