jar test sequence, more animation types

This commit is contained in:
Boblet 2022-08-23 16:08:31 +02:00
parent 1a1be50d3d
commit 53bcebfe97
9 changed files with 294 additions and 35 deletions

View File

@ -358,11 +358,10 @@ public class CentrifugeRecipes extends SerializableRecipe {
if(recipes.containsKey(comp))
return RecipesCommon.copyStackArray(recipes.get(comp));
String[] dictKeys = comp.getDictKeys();
for(String key : dictKeys) {
if(recipes.containsKey(new OreDictStack(key)))
return RecipesCommon.copyStackArray(recipes.get(key));
for(Entry<AStack, ItemStack[]> entry : recipes.entrySet()) {
if(entry.getKey().isApplicable(stack)) {
return RecipesCommon.copyStackArray(entry.getValue());
}
}
return null;

View File

@ -3,6 +3,9 @@ package com.hbm.wiaj;
import org.lwjgl.opengl.GL11;
import com.hbm.blocks.ModBlocks;
import com.hbm.wiaj.actions.ActionRotate;
import com.hbm.wiaj.actions.ActionSetBlock;
import com.hbm.wiaj.actions.ActionWait;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
@ -16,6 +19,8 @@ public class GuiWorldInAJar extends GuiScreen {
WorldInAJar world;
RenderBlocks renderer;
JarScript testScript;
public GuiWorldInAJar() {
super();
@ -23,55 +28,76 @@ public class GuiWorldInAJar extends GuiScreen {
renderer = new RenderBlocks(world);
renderer.enableAO = true;
testScript = new JarScript(world);
JarScene startingScene = new JarScene(testScript);
for(int x = 0; x < 15; x++) {
for(int y = 0; y < 15; y++) {
for(int z = 0; z < 15; z++) {
if(y == 14) {
world.setBlock(x, y, z, ModBlocks.glass_boron, 0);
startingScene.add(new ActionSetBlock(x, y, z, ModBlocks.glass_boron));
startingScene.add(new ActionWait(1));
continue;
}
if(y > 0) {
if(x == 0 || x == 14 || z == 0 || z == 14) {
world.setBlock(x, y, z, ModBlocks.glass_boron, 0);
startingScene.add(new ActionSetBlock(x, y, z, ModBlocks.glass_boron));
startingScene.add(new ActionWait(1));
continue;
}
}
if(y == 0) {
if(x == 0 || x == 14 || z == 0 || z == 14) {
world.setBlock(x, y, z, ModBlocks.concrete_colored, 6);
startingScene.add(new ActionSetBlock(x, y, z, ModBlocks.concrete_colored, 6));
} else {
world.setBlock(x, y, z, ModBlocks.concrete_smooth, 0);
startingScene.add(new ActionSetBlock(x, y, z, ModBlocks.concrete_colored, 0));
}
}
}
}
}
world.setBlock(2, 1, 2, ModBlocks.fallout, 0);
world.setBlock(4, 1, 4, ModBlocks.conveyor, 2);
world.setBlock(4, 1, 5, ModBlocks.conveyor, 2);
world.setBlock(4, 1, 6, ModBlocks.conveyor, 2);
world.setBlock(4, 1, 7, ModBlocks.conveyor, 2);
world.setBlock(4, 1, 8, ModBlocks.conveyor, 2);
world.setBlock(4, 1, 9, ModBlocks.conveyor, 2);
world.setBlock(4, 1, 10, ModBlocks.conveyor, 6);
world.setBlock(5, 1, 10, ModBlocks.conveyor, 4);
for(int x = 9; x < 12; x++) {
for(int y = 1; y < 5; y++) {
startingScene.add(new ActionWait(20));
startingScene.add(new ActionSetBlock(2, 1, 2, ModBlocks.fallout, 0));
startingScene.add(new ActionSetBlock(4, 1, 4, ModBlocks.conveyor, 2));
startingScene.add(new ActionSetBlock(4, 1, 5, ModBlocks.conveyor, 2));
startingScene.add(new ActionSetBlock(4, 1, 6, ModBlocks.conveyor, 2));
startingScene.add(new ActionSetBlock(4, 1, 7, ModBlocks.conveyor, 2));
startingScene.add(new ActionSetBlock(4, 1, 8, ModBlocks.conveyor, 2));
startingScene.add(new ActionSetBlock(4, 1, 9, ModBlocks.conveyor, 2));
startingScene.add(new ActionSetBlock(4, 1, 10, ModBlocks.conveyor, 6));
startingScene.add(new ActionSetBlock(5, 1, 10, ModBlocks.conveyor, 4));
startingScene.add(new ActionRotate(90, 0, 50));
JarScene brickScene = new JarScene(testScript);
for(int y = 1; y < 7; y++) {
for(int x = 9; x < 12; x++) {
for(int z = 6; z < 9; z++) {
world.setBlock(x, y, z, Blocks.brick_block, 0);
brickScene.add(new ActionSetBlock(x, y, z, Blocks.brick_block));
}
}
brickScene.add(new ActionWait(10));
}
brickScene.add(new ActionRotate(-90, 0, 20));
this.testScript.addScene(startingScene).addScene(brickScene);
}
@Override
public void drawScreen(int mouseX, int mouseY, float f) {
this.drawDefaultBackground();
if(testScript != null) {
testScript.run();
}
this.drawGuiContainerBackgroundLayer(f, mouseX, mouseY);
GL11.glDisable(GL11.GL_LIGHTING);
//this.drawGuiContainerForegroundLayer(mouseX, mouseY);
@ -85,12 +111,16 @@ public class GuiWorldInAJar extends GuiScreen {
GL11.glTranslated(width / 2, height / 2 + 70, 100);
GL11.glScaled(scale, scale, scale);
GL11.glScaled(1, 1, 0.01); // increadible flattening power
GL11.glRotated(30, -1, 0, 0);
GL11.glRotated(45, 0, -1, 0);
double pitch = testScript.lastRotationPitch + (testScript.rotationPitch - testScript.lastRotationPitch) * testScript.interp;
double yaw = testScript.lastRotationYaw + (testScript.rotationYaw - testScript.lastRotationYaw) * testScript.interp;
GL11.glRotated(pitch, 1, 0, 0);
GL11.glRotated(yaw, 0, 1, 0);
GL11.glTranslated(-7, 0 , -7);
GL11.glTranslated(world.sizeX / 2D, 0 , world.sizeZ / 2D);
GL11.glRotated(System.currentTimeMillis() % (360 * 20) / 20D, 0, -1, 0);
//GL11.glRotated(System.currentTimeMillis() % (360 * 20) / 20D, 0, -1, 0);
GL11.glTranslated(world.sizeX / -2D, 0 , world.sizeZ / -2D);
Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture);

View File

@ -0,0 +1,67 @@
package com.hbm.wiaj;
import java.util.ArrayList;
import java.util.List;
import com.hbm.wiaj.actions.IJarAction;
import net.minecraft.util.MathHelper;
/**
* A scene is a simple sequence of tasks, every script can have multiple scenes
* Scenes depend on each other, in order to rewind we'll have to re-init the playing field and FFW through all previous scenes
* @author hbm
*
*/
public class JarScene {
public List<IJarAction> actions = new ArrayList();
public JarScript script;
private int actionNumber = 0;
public IJarAction currentAction; //the action that is currently happening
public int currentActionStart = 0; //time in ticks since init
public JarScene (JarScript script) {
this.script = script;
}
public JarScene add(IJarAction action) {
if(this.currentAction == null)
this.currentAction = action; //set first action
this.actions.add(action);
return this;
}
/** does the once per 50ms tick routine */
public void tick() {
if(this.currentAction == null) return;
this.currentAction.act(script.world, this);
int duration = this.currentAction.getDuration();
if(this.currentActionStart + duration <= script.ticksElapsed) { //choose next action
this.actionNumber++;
this.currentActionStart = script.ticksElapsed;
if(actionNumber < this.actions.size()) {
this.currentAction = this.actions.get(actionNumber);
tick();
} else {
this.currentAction = null;
}
}
}
public void reset() {
this.currentAction = this.actions.get(0);
this.actionNumber = 0;
this.currentActionStart = script.ticksElapsed;
}
}

View File

@ -0,0 +1,100 @@
package com.hbm.wiaj;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.util.MathHelper;
public class JarScript {
public WorldInAJar world;
private List<JarScene> scenes = new ArrayList();
private JarScene currentScene;
private int sceneNumber = 0;
public double lastRotationYaw = -45D;
public double lastRotationPitch = -30D;
public double rotationYaw = -45D;
public double rotationPitch = -30D;
public float interp = 0F;
public long lastTick = 0;
public int ticksElapsed = 0;
private boolean isPaused = false;
public JarScript(WorldInAJar world) {
this.world = world;
}
public JarScript addScene(JarScene scene) {
if(this.currentScene == null)
this.currentScene = scene;
this.scenes.add(scene);
return this;
}
/**supposed to be called every frame, it calculates tick times and interp values */
public void run() {
long now = System.currentTimeMillis();
boolean nextTick = false;
if(this.lastTick == 0) { // do the first tick right away
this.lastTick = now;
nextTick = true;
}
if(this.lastTick + 50 < now) {
this.lastTick = now;
this.ticksElapsed++;
nextTick = true;
}
this.interp = MathHelper.clamp_float((float) (now - this.lastTick) / 50F, 0F, 1F);
if(nextTick) {
this.lastRotationPitch = this.rotationPitch;
this.lastRotationYaw = this.rotationYaw;
if(this.currentScene != null) {
tickScene();
}
}
}
public void tickScene() {
this.currentScene.tick();
if(this.currentScene.currentAction == null) { //means this scene is done
this.sceneNumber++;
if(this.sceneNumber < this.scenes.size()) {
this.currentScene = this.scenes.get(sceneNumber);
this.currentScene.currentActionStart = this.ticksElapsed;
} else {
this.currentScene = null;
}
}
}
private long pauseDelta;
public void pause() {
this.isPaused = true;
this.pauseDelta = System.currentTimeMillis() - this.lastTick; //saves the difference between last tick and now
}
public void unpause() {
this.isPaused = false;
this.lastTick = System.currentTimeMillis() - this.pauseDelta; //recreates an equivalent last tick from the new current time
}
public boolean isPaused() {
return this.isPaused;
}
}

View File

@ -0,0 +1,28 @@
package com.hbm.wiaj.actions;
import com.hbm.wiaj.JarScene;
import com.hbm.wiaj.WorldInAJar;
public class ActionRotate implements IJarAction {
int time;
double velYaw;
double velPitch;
public ActionRotate(double yaw, double pitch, int time) {
this.velYaw = yaw / time;
this.velPitch = pitch / time;
this.time = time;
}
@Override
public int getDuration() {
return this.time;
}
@Override
public void act(WorldInAJar world, JarScene scene) {
scene.script.rotationPitch += this.velPitch;
scene.script.rotationYaw += this.velYaw;
}
}

View File

@ -1,10 +1,15 @@
package com.hbm.wiaj.actions;
import com.hbm.wiaj.JarScene;
import com.hbm.wiaj.WorldInAJar;
import net.minecraft.block.Block;
public class ActionSetBlock implements IWorldAction {
/**
* Simple action that places one block instantly with no delay
* @author hmb
*/
public class ActionSetBlock implements IJarAction {
int x;
int y;
@ -25,7 +30,12 @@ public class ActionSetBlock implements IWorldAction {
}
@Override
public void act(WorldInAJar world) {
public void act(WorldInAJar world, JarScene scene) {
world.setBlock(x, y, z, b, meta);
}
@Override
public int getDuration() {
return 0;
}
}

View File

@ -0,0 +1,21 @@
package com.hbm.wiaj.actions;
import com.hbm.wiaj.JarScene;
import com.hbm.wiaj.WorldInAJar;
public class ActionWait implements IJarAction {
private int ticks;
public ActionWait(int ticks) {
this.ticks = ticks;
}
@Override
public int getDuration() {
return this.ticks;
}
@Override
public void act(WorldInAJar world, JarScene scene) { }
}

View File

@ -0,0 +1,12 @@
package com.hbm.wiaj.actions;
import com.hbm.wiaj.JarScene;
import com.hbm.wiaj.WorldInAJar;
public interface IJarAction {
/** Time taken by this action in ticks */
public int getDuration();
/** Perform this action */
public void act(WorldInAJar world, JarScene scene);
}

View File

@ -1,8 +0,0 @@
package com.hbm.wiaj.actions;
import com.hbm.wiaj.WorldInAJar;
public interface IWorldAction {
public void act(WorldInAJar world);
}