tile entity? put it in the jar

This commit is contained in:
Boblet 2022-08-24 16:48:55 +02:00
parent f57a6f35a4
commit df0693db12
11 changed files with 219 additions and 8 deletions

View File

@ -7,14 +7,16 @@ import com.hbm.blocks.ModBlocks;
import com.hbm.main.ResourceManager;
import com.hbm.render.item.ItemRenderBase;
import com.hbm.tileentity.machine.TileEntityStirling;
import com.hbm.wiaj.actors.ITileActorRenderer;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.client.IItemRenderer;
public class RenderStirling extends TileEntitySpecialRenderer implements IItemRendererProvider {
public class RenderStirling extends TileEntitySpecialRenderer implements IItemRendererProvider, ITileActorRenderer {
@Override
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float interp) {
@ -93,4 +95,49 @@ public class RenderStirling extends TileEntitySpecialRenderer implements IItemRe
RenderStirling.this.renderCommon(cog ? System.currentTimeMillis() % 3600 * 0.1F : 0, cog, item.getItem() == Item.getItemFromBlock(ModBlocks.machine_stirling) ? 0 : 1);
}};
}
@Override
public void renderActor(int ticks, float interp, NBTTagCompound data) {
double x = data.getDouble("x");
double y = data.getDouble("y");
double z = data.getDouble("z");
int rotation = data.getInteger("rotation");
int type = data.getInteger("type");
boolean hasCog = data.getBoolean("hasCog");
float lastSpin = data.getFloat("lastSpin");
float spin = data.getFloat("spin");
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5D, y, z + 0.5D);
switch(rotation) {
case 3: GL11.glRotatef(0, 0F, 1F, 0F); break;
case 5: GL11.glRotatef(90, 0F, 1F, 0F); break;
case 2: GL11.glRotatef(180, 0F, 1F, 0F); break;
case 4: GL11.glRotatef(270, 0F, 1F, 0F); break;
}
renderCommon(lastSpin + (spin - lastSpin) * interp, hasCog, type);
GL11.glPopMatrix();
}
@Override
public void updateActor(int ticks, NBTTagCompound data) {
float lastSpin = 0;
float spin = data.getFloat("spin");
float speed = data.getFloat("speed");
lastSpin = spin;
spin += speed;
if(spin >= 360) {
lastSpin -= 360;
spin -= 360;
}
data.setFloat("lastSpin", lastSpin);
data.setFloat("spin", spin);
}
}

View File

@ -1,11 +1,14 @@
package com.hbm.wiaj;
import java.util.Map.Entry;
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 com.hbm.wiaj.actors.ISpecialActor;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
@ -131,7 +134,6 @@ public class GuiWorldInAJar extends GuiScreen {
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.glTranslated(world.sizeX / -2D, 0 , world.sizeZ / -2D);
Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
@ -148,6 +150,11 @@ public class GuiWorldInAJar extends GuiScreen {
Tessellator.instance.draw();
GL11.glShadeModel(GL11.GL_FLAT);
for(Entry<Integer, ISpecialActor> actor : this.testScript.actors.entrySet()) {
actor.getValue().draw(this.testScript.ticksElapsed, this.testScript.interp);
}
GL11.glPopMatrix();
}

View File

@ -5,8 +5,6 @@ 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

View File

@ -3,6 +3,7 @@ package com.hbm.wiaj;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import com.hbm.wiaj.actors.ISpecialActor;
@ -12,7 +13,7 @@ public class JarScript {
public WorldInAJar world;
private List<JarScene> scenes = new ArrayList();
private HashMap<Integer, ISpecialActor> actors = new HashMap();
public HashMap<Integer, ISpecialActor> actors = new HashMap();
private JarScene currentScene;
private int sceneNumber = 0;
@ -61,10 +62,16 @@ public class JarScript {
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) {
for(Entry<Integer, ISpecialActor> actor : this.actors.entrySet()) {
actor.getValue().updateActor(this.currentScene);
}
tickScene();
}
}

View File

@ -0,0 +1,26 @@
package com.hbm.wiaj.actions;
import com.hbm.wiaj.JarScene;
import com.hbm.wiaj.WorldInAJar;
import com.hbm.wiaj.actors.ISpecialActor;
public class ActionCreateActor implements IJarAction {
int id;
ISpecialActor actor;
public ActionCreateActor(int id, ISpecialActor actor) {
this.id = id;
this.actor = actor;
}
@Override
public int getDuration() {
return 0;
}
@Override
public void act(WorldInAJar world, JarScene scene) {
scene.script.actors.put(id, actor);
}
}

View File

@ -0,0 +1,23 @@
package com.hbm.wiaj.actions;
import com.hbm.wiaj.JarScene;
import com.hbm.wiaj.WorldInAJar;
public class ActionRemoveActor implements IJarAction {
int id;
public ActionRemoveActor(int id) {
this.id = id;
}
@Override
public int getDuration() {
return 0;
}
@Override
public void act(WorldInAJar world, JarScene scene) {
scene.script.actors.remove(id);
}
}

View File

@ -0,0 +1,27 @@
package com.hbm.wiaj.actions;
import com.hbm.wiaj.JarScene;
import com.hbm.wiaj.WorldInAJar;
import net.minecraft.nbt.NBTTagCompound;
public class ActionSetActorData implements IJarAction {
int id;
NBTTagCompound data;
public ActionSetActorData(int id, NBTTagCompound data) {
this.id = id;
this.data = data;
}
@Override
public int getDuration() {
return 0;
}
@Override
public void act(WorldInAJar world, JarScene scene) {
scene.script.actors.get(id).setActorData(data);
}
}

View File

@ -0,0 +1,27 @@
package com.hbm.wiaj.actions;
import com.hbm.wiaj.JarScene;
import com.hbm.wiaj.WorldInAJar;
public class ActionUpdateActor implements IJarAction {
int id;
String key;
Object data;
public ActionUpdateActor(int id, String key, Object data) {
this.id = id;
this.key = key;
this.data = data;
}
@Override
public int getDuration() {
return 0;
}
@Override
public void act(WorldInAJar world, JarScene scene) {
scene.script.actors.get(id).setDataPoint(key, data);
}
}

View File

@ -0,0 +1,38 @@
package com.hbm.wiaj.actors;
import com.hbm.wiaj.JarScene;
import net.minecraft.nbt.NBTTagCompound;
public class ActorTileEntity implements ISpecialActor {
ITileActorRenderer renderer;
NBTTagCompound data = new NBTTagCompound();
public ActorTileEntity(ITileActorRenderer renderer) {
this.renderer = renderer;
}
@Override
public void draw(int ticks, float interp) {
renderer.renderActor(ticks, interp, data);
}
@Override
public void updateActor(JarScene scene) {
renderer.updateActor(scene.script.ticksElapsed, data);
}
@Override
public void setActorData(NBTTagCompound data) {
this.data = data;
}
@Override
public void setDataPoint(String tag, Object o) {
if(o instanceof String) this.data.setString(tag, (String) o);
if(o instanceof Integer) this.data.setInteger(tag, (Integer) o);
if(o instanceof Float) this.data.setFloat(tag, (Float) o);
if(o instanceof Double) this.data.setDouble(tag, (Double) o);
}
}

View File

@ -2,9 +2,17 @@ package com.hbm.wiaj.actors;
import com.hbm.wiaj.JarScene;
import net.minecraft.nbt.NBTTagCompound;
/**
* Actors, anything that can receive ticks (for rendering movement for example) and renders on screen
* Can be tile entity models, faux entities or tooltips
* @author hbm
*/
public interface ISpecialActor {
public void draw();
public void draw(int ticks, float interp);
public void updateActor(JarScene scene);
public void setActorData(Object... data);
public void setActorData(NBTTagCompound data);
public void setDataPoint(String tag, Object o);
}

View File

@ -1,6 +1,9 @@
package com.hbm.wiaj.actors;
import net.minecraft.nbt.NBTTagCompound;
public interface ITileActorRenderer {
public void renderActor(Object... data);
public void renderActor(int ticks, float interp, NBTTagCompound data);
public void updateActor(int ticks, NBTTagCompound data);
}