Skip to content

Commit

Permalink
Merge pull request #28 from lebonq/lebonq/issue27
Browse files Browse the repository at this point in the history
Permanent path
  • Loading branch information
lebonq authored May 26, 2021
2 parents 6c1b31b + 621eb62 commit 6919add
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ yarn_mappings=1.16.5+build.9
loader_version=0.11.3

#Mod properties
mod_version = 1.3.5
mod_version = 1.4.0
maven_group = fr.lebon
archives_base_name = autopath

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/fr/lebon/autopath/config/AutoPathConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
@Config(name = "autopath")
public class AutoPathConfig implements ConfigData {
@ConfigEntry.Gui.Tooltip()
public int downgradeTime = 360;
public int downgradeTime = 760;
@ConfigEntry.Gui.Tooltip()
public int upgradeTime = 120;
public int upgradeTime = 280;
@ConfigEntry.Gui.Tooltip()
public boolean permanentPath = true;
@ConfigEntry.Gui.Tooltip()
public int steppedBeforePermanent = 12;

}
25 changes: 24 additions & 1 deletion src/main/java/fr/lebon/autopath/entity/PathEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,31 @@

public class PathEntity extends BlockEntity implements Tickable{

private int nbTick; //Game will crash after 3years non stop of existing for the block
private int downgradeTime;
private int upgradeTime;
private boolean permanentActivate;
private int steppedBeforePermanent;

private boolean permanent;
private int timesWalkOn;
private int nbTick; //Game will crash after 3years non stop of existing for the block

public PathEntity() {
super(AutoPath.PATH_ENTITY);

AutoPathConfig config = AutoConfig.getConfigHolder(AutoPathConfig.class).getConfig();
downgradeTime = config.downgradeTime*20;//GEt time and converte from second to int
upgradeTime = config.upgradeTime*20;
permanentActivate = config.permanentPath;
steppedBeforePermanent = config.steppedBeforePermanent;
}

@Override
public void tick() {//20 ticks 1 seconde
if(permanent){
return; //Si permanent on ne fait plus rien
}

if(world.isClient()) return;

if(world.getBlockState(pos.up()).isSolidBlock(world, pos.up())){//si le block au dessus est solide
Expand All @@ -36,6 +47,7 @@ public void tick() {//20 ticks 1 seconde
int currentRenderState = world.getBlockState(pos).get(PathBlock.STATE_RENDER);

if(nbTick >= downgradeTime){//7200
timesWalkOn = 0;
if(currentRenderState - 1 <= 0){
world.setBlockState(pos, Blocks.GRASS_BLOCK.getDefaultState());//On place un block de grass
return; //Le block est detruit
Expand All @@ -53,6 +65,13 @@ public void tick() {//20 ticks 1 seconde
}

if(world.getBlockState(pos).get(PathBlock.STEPPED) && currentRenderState == 5){
if(timesWalkOn == steppedBeforePermanent){
permanent = true;
}

if(permanentActivate){
timesWalkOn++;
}
nbTick = 0;
}

Expand All @@ -64,6 +83,8 @@ public void tick() {//20 ticks 1 seconde
public CompoundTag toTag(CompoundTag tag) {
super.toTag(tag);
tag.putInt("nbTick", nbTick);
tag.putBoolean("permanent", permanent);
tag.putInt("timesWalkOn", timesWalkOn);

return tag;
}
Expand All @@ -72,5 +93,7 @@ public CompoundTag toTag(CompoundTag tag) {
public void fromTag(BlockState state, CompoundTag tag) {
super.fromTag(state, tag);
nbTick = tag.getInt("nbTick");
permanent = tag.getBoolean("permanent");
timesWalkOn = tag.getInt("timesWalkOn");
}
}
6 changes: 5 additions & 1 deletion src/main/resources/assets/autopath/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
"text.autoconfig.autopath.option.downgradeTime" : "Downgrade Time",
"text.autoconfig.autopath.option.downgradeTime.@Tooltip" : "Time in seconds the path will become more grassier",
"text.autoconfig.autopath.option.upgradeTime" : "Upgrade Time",
"text.autoconfig.autopath.option.upgradeTime.@Tooltip" : "Time in seconds the path will become more grassless"
"text.autoconfig.autopath.option.upgradeTime.@Tooltip" : "Time in seconds the path will become more grassless",
"text.autoconfig.autopath.option.permanentPath" : "Permanent path",
"text.autoconfig.autopath.option.permanentPath.@Tooltip" : "Enable permanent path",
"text.autoconfig.autopath.option.steppedBeforePermanent" : "Number of step until permanent",
"text.autoconfig.autopath.option.steppedBeforePermanent.@Tooltip" : "Number of times the block is stepped before becoming permanent"
}

0 comments on commit 6919add

Please sign in to comment.