Solved Manipulate MC time.

Discussion in 'Plugin Development' started by BeastyBoo, Oct 14, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    BeastyBoo

    Hey, im trying to make a method that either speeds up or slows down the minecraft day and night depending on the values in my own world object. I figured out how to speed it up, but I dont understand how I can slow it down in the same method, like many other plugins do. An example is this plugin: https://github.com/Zedly/VariableTime/blob/master/src/main/java/zedly/variabletime/VariableTime.java

    This is my current method:

    Code:
    public void manipulateTime(){
            core.getPlugin().getServer().getScheduler().scheduleSyncRepeatingTask(core.getPlugin(), new Runnable() {
                @Override
                public void run() {
                    for(WorldModel data : getWorlds()) {
                        World world = Bukkit.getWorld(data.getWorldName());
                        if(world != null) {
                            long time = world.getTime();
    
                            if(time <= 13000) {
                                if ((data.getDayMultiplier() > 0.0D) && (data.getDayMultiplier() < 1.0D)) {
                                    //Slow down the day?
                                } else if (data.getDayMultiplier() >= 1.0D) {
                                    double newTime = time + data.getDayMultiplier();
                                    world.setTime((long) newTime);
                                }
                            }
                            else if(time > 13000) {
                                if ((data.getNightMultiplier() > 0.0D) && (data.getNightMultiplier() < 1.0D)) {
                                    //Slow down the night?
                                } else if (data.getNightMultiplier() >= 1.0D) {
                                    double newTime = time + data.getNightMultiplier();
                                    world.setTime((long) newTime);
                                }
                            }
                            //?data.tick += 1L;
                        }
                    }
                }
            }, 0L, 1L);
        }
    My WorldModel class:

    Code:
    public class WorldModel {
    
        private final String worldName;
        private int dayDuration;
        private int nightDuration;
    
        public WorldModel(String worldName, int dayDuration, int nightDuration) {
            this.worldName = worldName;
            this.dayDuration = dayDuration;
            this.nightDuration = nightDuration;
        }
    
        public String getWorldName() {
            return worldName;
        }
    
        public int getDayDuration() {
            return dayDuration;
        }
    
        public void setDayDuration(int dayDuration) {
            this.dayDuration = dayDuration;
        }
    
        public int getNightDuration() {
            return nightDuration;
        }
    
        public void setNightDuration(int nightDuration) {
            this.nightDuration = nightDuration;
        }
    
        public double getDayMultiplier(){
            return 13000/getDayDuration();
        }
    
        public double getNightMultiplier(){
            return 11000/getNightDuration();
        }
    
        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
    
            WorldModel that = (WorldModel) o;
    
            if (getDayDuration() != that.getDayDuration()) return false;
            if (getNightDuration() != that.getNightDuration()) return false;
            return getWorldName().equals(that.getWorldName());
        }
    
        @Override
        public int hashCode() {
            int result = getWorldName().hashCode();
            result = 31 * result + getDayDuration();
            result = 31 * result + getNightDuration();
            return result;
        }
    }
     
  2. Offline

    BeastyBoo

    BUMP

    I managed to fix some values, but still can't slow down the time. This is the part where I try to slow down the day.Any help please?
    Code:
    double mult = data.getDayMultiplier();
                            if ((mult > 0.0D) && (mult < 1.0D)) {
                                //TODO: Help, this part dont work..
                                double offset = time * mult;
                                double newTime = time - offset;
                                world.setTime((long)newTime);
                            }
     
Thread Status:
Not open for further replies.

Share This Page