Skip to content

Commit

Permalink
remove individually welcome screen, implements JoinTime and QuitTime …
Browse files Browse the repository at this point in the history
…to add and remove items automatically
  • Loading branch information
kuzuanpa committed Sep 27, 2024
1 parent 009e3b6 commit 5307473
Show file tree
Hide file tree
Showing 21 changed files with 330 additions and 318 deletions.
29 changes: 20 additions & 9 deletions src/main/java/blockrenderer6343/client/WorldSceneRenderer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package blockrenderer6343.client;

import static cn.kuzuanpa.thinker.client.handler.dummyWorldHandler.dummyWorldObjects;
import static org.lwjgl.opengl.GL11.*;

import java.nio.ByteBuffer;
Expand Down Expand Up @@ -137,12 +136,22 @@ public void setCameraLookAt(Vector3f eyePos, Vector3f lookAt, Vector3f worldUp)
public boolean sync(){
if(world.lock) return false;
if(world instanceof TrackedDummyWorld)((TrackedDummyWorld) world).clearBlocks();
List<IdummyWorldThinkerObject> tmp = new ArrayList<>();
dummyWorldHandler.dummyWorldObjects.forEach((obj) -> tmp.addAll(obj.addToWorld(world)));
dummyWorldHandler.dummyWorldObjects.addAll( tmp);
if(world instanceof TrackedDummyWorld)((TrackedDummyWorld) world).onProfileChanged();
return true;
}

public void onTick(){
world.lock=true;
List<IdummyWorldThinkerObject> tmp = new ArrayList<>();
List<IdummyWorldThinkerObject> tmp1 = new ArrayList<>();
dummyWorldHandler.getDummyWorldObjects("WorldSceneRenderer.onTick:147").forEach((obj) -> {
if(obj.shouldInWorld(world.timer)){if(!obj.alreadyInWorld())tmp.addAll(obj.addToWorld(world));
}else if(obj.alreadyInWorld())tmp1.addAll(obj.removeFromWorld(world));
});
dummyWorldHandler.getDummyWorldObjects("WorldSceneRenderer.onTick:151").addAll( tmp);
dummyWorldHandler.getDummyWorldObjects("WorldSceneRenderer.onTick:152").removeAll( tmp1);
world.lock=false;
}
public void setCameraLookAt(Vector3f lookAt, double radius, double rotationPitch, double rotationYaw) {
this.lookAt = lookAt;
Vector3 vecX = new Vector3(Math.cos(rotationPitch), 0, Math.sin(rotationPitch));
Expand Down Expand Up @@ -254,7 +263,7 @@ void renderSceneForPicking() {
glInitNames();
glPushName(-1);

for (IdummyWorldThinkerObject obj : dummyWorldObjects) {
for (IdummyWorldThinkerObject obj : dummyWorldHandler.getDummyWorldObjects("WorldSceneRenderer.renderSceneForPicking:266")) {
try {

glEnable(GL_DEPTH_TEST);
Expand Down Expand Up @@ -321,13 +330,15 @@ protected void drawWorld() {
glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST);
glEnable(GL_DEPTH_TEST);
dummyWorldObjects.forEach((obj) -> {
world.lock=true;
dummyWorldHandler.getDummyWorldObjects("WorldSceneRenderer.drawWorld:333").forEach((obj) -> {
try {
obj.render(world, world.timer, null);
if(obj.shouldInWorld(world.timer))obj.render(world, world.timer, null);
} catch (Exception e) {
Thinker.err(e);
}
});
world.lock=false;

//onMouseMoved(Mouse.getX(),Mouse.getY());

Expand Down Expand Up @@ -359,7 +370,7 @@ public MovingObjectPosition rayTrace(Vector3f hitPos,BlockPosition pos) {
(hitPos.y - startPos.yCoord),
(hitPos.z - startPos.zCoord));

return ((TrackedDummyWorld) this.world).rayTraceBlockswithTargetMap(startPos, endPos,dummyWorldHandler.dummyWorldObjects.stream().map(IdummyWorldThinkerObject::getPos).collect(Collectors.toSet()), pos);
return ((TrackedDummyWorld) this.world).rayTraceBlockswithTargetMap(startPos, endPos,dummyWorldHandler.getDummyWorldObjects("WorldSceneRenderer.rayTrace:371").stream().map(IdummyWorldThinkerObject::getPos).collect(Collectors.toSet()), pos);
}

/***
Expand All @@ -377,7 +388,7 @@ protected MovingObjectPosition screenPos2BlockPosFace(int mouseX, int mouseY, in
drawWorld();

AtomicReference<MovingObjectPosition> result = new AtomicReference<>();
dummyWorldHandler.dummyWorldObjects.forEach((blockDummy)->{
dummyWorldHandler.getDummyWorldObjects("WorldSceneRenderer.screenPos2BlockPosFace:389").forEach((blockDummy)->{
BlockPosition pos = blockDummy.getPos();
GL11.glPushMatrix();
if(!blockDummy.getWorldAnimeList().isEmpty())blockDummy.getWorldAnimeList().forEach(gAnime->{
Expand Down
9 changes: 1 addition & 8 deletions src/main/java/blockrenderer6343/world/DummyWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ public DummyWorld() {
}
@Override
public void updateEntities() {
if(!lock)System.out.println("World missing lock when ticking!");
ArrayList<TileEntity> invalidTileEntities = new ArrayList<>();

for (IdummyWorldThinkerObject o : dummyWorldHandler.dummyWorldObjects) {
for (IdummyWorldThinkerObject o : dummyWorldHandler.getDummyWorldObjects("DummyWorld.updateEntities:51")) {

if(o.getWorldAnimeList().stream().filter(anime -> anime instanceof IDummyWorldTickingAnime).anyMatch(anime -> ((IDummyWorldTickingAnime) anime).beforeTick(timer, o, this)))return;

Expand Down Expand Up @@ -76,12 +75,6 @@ public void updateEntities() {
this.loadedTileEntityList.removeAll(invalidTileEntities);

}
public void updateEntitiesForNEI() {
lock=true;
super.updateEntities();
lock=false;
}

@Override
public void markBlockRangeForRenderUpdate(int x1, int y1, int z1, int x2, int y2, int z2) {}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/blockrenderer6343/world/DummyWorldTickThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cn.kuzuanpa.thinker.Thinker;
import cn.kuzuanpa.thinker.client.handler.configHandler;
import cn.kuzuanpa.thinker.client.handler.dummyWorldHandler;

public class DummyWorldTickThread extends Thread{
@Override
Expand All @@ -18,13 +19,13 @@ public DummyWorldTickThread() {
@Override
public void run() {
while (true) {
if(trackedDummyWorld!=null&&(int)Math.abs((System.currentTimeMillis()%100000)-lastTickTime) > intervalBetweenTicks){
if(trackedDummyWorld!=null&&!trackedDummyWorld.lock&&(int)Math.abs((System.currentTimeMillis()%100000)-lastTickTime) > intervalBetweenTicks){
lastTickTime = (int)(System.currentTimeMillis()%100000);
trackedDummyWorld.lock=true;

try {
trackedDummyWorld.updateEntities();
}catch (Exception e){Thinker.err("Exception occurred when ticking Dummy world");e.printStackTrace();}
trackedDummyWorld.lock=false;
}catch (Exception e){Thinker.err("Exception occurred when ticking Dummy world, Previous user:"+ dummyWorldHandler.ObjectListUser);e.printStackTrace();}

if(configHandler.recordDummyWorldTickTooLong.get()&&System.currentTimeMillis()%100000-lastTickTime>2*intervalBetweenTicks)System.out.println("A Tick of DummyWorld takes too long: "+(System.currentTimeMillis()%100000-lastTickTime)+"ms");
}else {
try {
Expand All @@ -35,7 +36,6 @@ public void run() {
}
public void setTrackedDummyWorld(DummyWorld world){
trackedDummyWorld=world;
if(world!=null)world.lock=true;
this.interrupt();
}
}
33 changes: 22 additions & 11 deletions src/main/java/cn/kuzuanpa/thinker/Thinker.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,54 +17,64 @@
import blockrenderer6343.world.DummyWorldTickThread;
import cn.kuzuanpa.thinker.client.handler.configHandler;
import cn.kuzuanpa.thinker.client.json.*;
import cn.kuzuanpa.thinker.client.ThinkingGuiWelcome;
import cn.kuzuanpa.thinker.command.CommandGetTileNBT;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.*;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraftforge.common.MinecraftForge;
import org.apache.logging.log4j.Level;
import org.spongepowered.asm.mixin.MixinEnvironment;

import static cn.kuzuanpa.thinker.client.json.thinkerJsonReader.animesAdaptors;
import static cn.kuzuanpa.thinker.client.json.thinkerJsonReader.objectsAdaptors;

@Mod(modid = Thinker.MOD_ID, version = Thinker.VERSION, dependencies = "required-after:CodeChickenCore@[1.0.7,);after:geckolib3")
@Mod(modid = Thinker.MOD_ID, version = Thinker.VERSION, dependencies = "required-after:CodeChickenCore@[1.0.7,)")
public class Thinker
{
public static final String MOD_ID = "thinker";
public static final String MOD_NAME = "Thinker";
public static final String VERSION = "0.0.1";
public static final DummyWorldTickThread dummyWorldTickThread=new DummyWorldTickThread();
public static int delay = 5;
public static boolean isGeckoLibLoaded=false;
public static boolean isGeckoLibLoaded=false,isServerSide=false;
@SidedProxy(clientSide = "cn.kuzuanpa.thinker.clientProxy",
serverSide = "cn.kuzuanpa.thinker.commonProxy")
public static commonProxy PROXY;

@EventHandler
public void preInit(FMLPreInitializationEvent event){
isServerSide=MinecraftServer.getServer() instanceof DedicatedServer;
isGeckoLibLoaded= Loader.isModLoaded("geckolib3");
if(isServerSide){
FMLLog.log(Level.ERROR,"Thinker is an CLIENT only mod, and will disable entirely in Server!");
return;
}
FMLCommonHandler.instance().bus().register(this);
MinecraftForge.EVENT_BUS.register(this);
configHandler.preInit(event);
}
@EventHandler
public void init(FMLInitializationEvent event)
{
if(isServerSide)return;
PROXY.init(event);
try {
thinkerJsonReader.readAllProfiles("ideas");}catch (Exception ignored){}

dummyWorldTickThread.start();
configHandler.saveAll();
registerObjectAdaptor(new defaultObjectsAdaptor());
registerAnimeAdaptor(new defaultAnimeAdaptor());
registerAnimeAdaptor(new defaultAnimeAdaptor());try {
thinkerJsonReader.readAllProfiles("ideas");
}catch (Exception ignored){}
}
@EventHandler
public void registerCommands(FMLServerStartingEvent e){
Expand Down Expand Up @@ -93,13 +103,14 @@ public static float getFloat(Object str){
}
public static boolean getBoolean(Object str){return Boolean.parseBoolean((String) str);}

@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onClientTick(TickEvent.ClientTickEvent event) {
if(!configHandler.welcome.get())return;
if (delay > 0 && event.phase == TickEvent.Phase.END) {
--delay;
if (delay == 0) {
FMLClientHandler.instance().getClient().displayGuiScreen(new ThinkingGuiWelcome());
FMLClientHandler.instance().getClient().displayGuiScreen(new cn.kuzuanpa.thinker.client.ThinkingGuiMain("HelloThinker"));
configHandler.welcome.set(false);
configHandler.welcome.save();
}
Expand Down
57 changes: 34 additions & 23 deletions src/main/java/cn/kuzuanpa/thinker/client/ThinkingGuiMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,19 @@ public ThinkingGuiMain(ItemStack item) {
allowUserInput = false;
selectedProfileID = profileHandler.getProfileFromItem(item.getUnlocalizedName()).id;
}
public ThinkingGuiMain(String id) {
openByUser=true;
allowUserInput = false;
selectedProfileID =id;
}
public DummyWorldButton worldButton= new DummyWorldButton(1,0,0,displayWidth,displayHeight);
public void onOpenByUserAfter(){
initTime=System.currentTimeMillis();
openByUser=false;
if(!selectedProfileID.equals(""))onProfileChanged(selectedProfileID);
if(!selectedProfileID.isEmpty()){
onProfileChanged(selectedProfileID);
foldThemeSelector(true);
}
}
public void initGui() {
super.initGui();
Expand Down Expand Up @@ -119,20 +127,20 @@ protected void keyTyped(char p_73869_1_, int p_73869_2_)
@Override
protected void mouseClicked(int p_73864_1_, int p_73864_2_, int mouseButton)
{
for (int l = this.buttonList.size() - 1; l >= 0 ;l--)
{
ThinkerButtonBase guibutton = (ThinkerButtonBase)this.buttonList.get(l);
if(guibutton.updateHoverState(p_73864_1_, p_73864_2_))
{
GuiScreenEvent.ActionPerformedEvent.Pre event = new GuiScreenEvent.ActionPerformedEvent.Pre(this, guibutton, this.buttonList);
if (MinecraftForge.EVENT_BUS.post(event))
break;
if(event.button.id!=0)event.button.func_146113_a(this.mc.getSoundHandler());
if (this.onButtonPressed(event.button)) break;
if (this.equals(this.mc.currentScreen))
MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.ActionPerformedEvent.Post(this, event.button, this.buttonList));
}
}
for (int l = this.buttonList.size() - 1; l >= 0 ;l--)
{
ThinkerButtonBase guibutton = (ThinkerButtonBase)this.buttonList.get(l);
if(guibutton.updateHoverState(p_73864_1_, p_73864_2_))
{
GuiScreenEvent.ActionPerformedEvent.Pre event = new GuiScreenEvent.ActionPerformedEvent.Pre(this, guibutton, this.buttonList);
if (MinecraftForge.EVENT_BUS.post(event))
break;
if(event.button.id!=0)event.button.func_146113_a(this.mc.getSoundHandler());
if (this.onButtonPressed(event.button)) break;
if (this.equals(this.mc.currentScreen))
MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.ActionPerformedEvent.Post(this, event.button, this.buttonList));
}
}
}
protected void onProfileChanged(String newProfileID){
initTime=System.currentTimeMillis();
Expand All @@ -148,7 +156,7 @@ protected void onProfileChanged(String newProfileID){
selectedProfileID =newProfileID;
}
protected boolean onButtonPressed(GuiButton button) {
((DummyWorldButton)buttonList.get(1)).clickOnOtherButton=button.id!=1;
((DummyWorldButton)buttonList.get(1)).clickOnOtherButton=button.id!=1&&button.id<10;
if(button.id==2) this.mc.displayGuiScreen(new ThinkerSettingsGui());
if(button.id==3) {
int mouseY=this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
Expand All @@ -167,15 +175,18 @@ protected boolean onButtonPressed(GuiButton button) {
return true;
}
public void foldThemeSelector(boolean immediately){
((ThinkerButtonBase)buttonList.get(3)).addAnime(new animeMoveLinear((int) (System.currentTimeMillis()-initTime)-(immediately?10:0), (int) (System.currentTimeMillis()-initTime+ (immediately?0:configHandler.getConfiguredAnimeTime(500))),-80-8*currentProfileLayer,0));
((ThinkerButtonBase)buttonList.get(4)).addAnime(new animeMoveLinear((int) (System.currentTimeMillis()-initTime)-(immediately?10:0), (int) (System.currentTimeMillis()-initTime+ (immediately?0:configHandler.getConfiguredAnimeTime(500))),-80-8*currentProfileLayer,0));
((ThinkerButtonBase)buttonList.get(5)).addAnime(new animeMoveLinear((int) (System.currentTimeMillis()-initTime)-(immediately?10:0), (int) (System.currentTimeMillis()-initTime+ (immediately?0:configHandler.getConfiguredAnimeTime(200))),16,0));
((ThinkerButtonBase)buttonList.get(3)).getGuiAnimeList().clear();
((ThinkerButtonBase)buttonList.get(4)).getGuiAnimeList().clear();
((ThinkerButtonBase)buttonList.get(5)).getGuiAnimeList().clear();
((ThinkerButtonBase)buttonList.get(3)).addAnime(new animeMoveLinear((int) getTimer()-(immediately?10:0), (int) (getTimer()+ (immediately?0:configHandler.getConfiguredAnimeTime(500))),-80-8*currentProfileLayer,0));
((ThinkerButtonBase)buttonList.get(4)).addAnime(new animeMoveLinear((int) getTimer()-(immediately?10:0), (int) (getTimer()+ (immediately?0:configHandler.getConfiguredAnimeTime(500))),-80-8*currentProfileLayer,0));
((ThinkerButtonBase)buttonList.get(5)).addAnime(new animeMoveLinear((int) getTimer()-(immediately?10:0), (int) (getTimer()+ (immediately?0:configHandler.getConfiguredAnimeTime(200))),16,0));
themeSelectorFolded=true;
}
public void unfoldThemeSelector(){
((ThinkerButtonBase)buttonList.get(3)).addAnime(new animeMoveLinear((int) (System.currentTimeMillis()-initTime), (int) (System.currentTimeMillis()-initTime+ configHandler.getConfiguredAnimeTime(500)),80+8*currentProfileLayer,0));
((ThinkerButtonBase)buttonList.get(4)).addAnime(new animeMoveLinear((int) (System.currentTimeMillis()-initTime), (int) (System.currentTimeMillis()-initTime+ configHandler.getConfiguredAnimeTime(500)),80+8*currentProfileLayer,0));
((ThinkerButtonBase)buttonList.get(5)).addAnime(new animeMoveLinear((int) (System.currentTimeMillis()-initTime), (int) (System.currentTimeMillis()-initTime+ configHandler.getConfiguredAnimeTime(200)),-16,0));
((ThinkerButtonBase)buttonList.get(3)).addAnime(new animeMoveLinear((int) getTimer(), (int) (getTimer()+ configHandler.getConfiguredAnimeTime(500)),80+8*currentProfileLayer,0));
((ThinkerButtonBase)buttonList.get(4)).addAnime(new animeMoveLinear((int) getTimer(), (int) (getTimer()+ configHandler.getConfiguredAnimeTime(500)),80+8*currentProfileLayer,0));
((ThinkerButtonBase)buttonList.get(5)).addAnime(new animeMoveLinear((int) getTimer(), (int) (getTimer()+ configHandler.getConfiguredAnimeTime(200)),-16,0));
themeSelectorFolded=false;
}
public void handleMouseInput(){
Expand All @@ -202,7 +213,7 @@ public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_){
if(!button.visible)return;
if(button.updateHoverState(x,y))hoveringString= Collections.singletonList(button.displayString);
});
if (hoveringString == null||hoveringString.stream().allMatch(string->string.equals(""))) return;
if (hoveringString == null||hoveringString.stream().allMatch(String::isEmpty)) return;
drawHoveringText(hoveringString, x, y+5, fontRendererObj);
}
public boolean close() {
Expand Down
Loading

0 comments on commit 5307473

Please sign in to comment.