Skip to content

Commit

Permalink
sync from 1.21.3-0.22.2-sakura.6
Browse files Browse the repository at this point in the history
  • Loading branch information
TexBlock committed Dec 14, 2024
1 parent 93d5d61 commit 1844453
Show file tree
Hide file tree
Showing 19 changed files with 2,780 additions and 879 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
## Change
- sync from 1.21.3-0.22.0-sakura.4
- sync from 1.21.3-0.22.2-sakura.6
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ For more information and the downloads (compiled builds), see releases
- Open a command prompt/terminal to the repository directory
- run 'gradlew build'
- The built jar file will be in build/libs/

## Credits
- [maruohon/tweakeroo](https://github.com/maruohon/tweakeroo)
- [sakura-ryoko/tweakeroo](https://github.com/sakura-ryoko/tweakeroo)
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
minecraft_version="1.21.3"
yarn_mappings="1.21.3+build.2"
mappings_patch="1.21+build.4"
neoforge="21.3.2-beta"
neoforge="21.3.58"

# Mod properties
version="0.1.9"
version="0.1.10"
maven-group="org.thinkingstudio.tweakerge"
archives-name="Tweakerge"

Expand All @@ -15,7 +15,7 @@ id-modrinth="yke6wdGF"
id-curseforge="915857"

# Mod dependencies
mafglib="0.1.24-mc1.21.3"
mafglib="0.2.1-mc1.21.3"
badpackets="neo-0.8.1"

# Libraries
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/fi/dy/masa/tweakeroo/InitHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import fi.dy.masa.malilib.interfaces.IInitializationHandler;
import fi.dy.masa.malilib.interfaces.IRenderer;
import fi.dy.masa.malilib.interfaces.IWorldLoadListener;
import fi.dy.masa.malilib.registry.Registry;
import fi.dy.masa.malilib.util.data.ModInfo;
import fi.dy.masa.tweakeroo.config.Callbacks;
import fi.dy.masa.tweakeroo.config.Configs;
import fi.dy.masa.tweakeroo.data.DataManager;
Expand All @@ -14,13 +16,17 @@
import fi.dy.masa.tweakeroo.event.InputHandler;
import fi.dy.masa.tweakeroo.event.RenderHandler;
import fi.dy.masa.tweakeroo.event.WorldLoadListener;
import fi.dy.masa.tweakeroo.gui.GuiConfigs;

public class InitHandler implements IInitializationHandler
{
@Override
public void registerModHandlers()
{
ConfigManager.getInstance().registerConfigHandler(Reference.MOD_ID, new Configs());
Registry.CONFIG_SCREEN.registerConfigScreenFactory(
new ModInfo(Reference.MOD_ID, Reference.MOD_NAME, GuiConfigs::new)
);
ServerDataSyncer.getInstance().onGameInit();

InputEventHandler.getKeybindManager().registerKeybindProvider(InputHandler.getInstance());
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/fi/dy/masa/tweakeroo/config/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@
import fi.dy.masa.malilib.config.IConfigBase;
import fi.dy.masa.malilib.config.IConfigHandler;
import fi.dy.masa.malilib.config.IHotkeyTogglable;
import fi.dy.masa.malilib.config.options.ConfigBoolean;
import fi.dy.masa.malilib.config.options.ConfigBooleanHotkeyed;
import fi.dy.masa.malilib.config.options.ConfigColor;
import fi.dy.masa.malilib.config.options.ConfigDouble;
import fi.dy.masa.malilib.config.options.ConfigInteger;
import fi.dy.masa.malilib.config.options.ConfigOptionList;
import fi.dy.masa.malilib.config.options.ConfigString;
import fi.dy.masa.malilib.config.options.ConfigStringList;
import fi.dy.masa.malilib.config.options.*;
import fi.dy.masa.malilib.util.ActiveMode;
import fi.dy.masa.malilib.util.FileUtils;
import fi.dy.masa.malilib.util.JsonUtils;
Expand Down Expand Up @@ -109,8 +102,10 @@ public static class Generic
public static final ConfigInteger RENDER_LIMIT_ITEM = new ConfigInteger ("renderLimitItem", -1, -1, 10000).apply(GENERIC_KEY);
public static final ConfigInteger RENDER_LIMIT_XP_ORB = new ConfigInteger ("renderLimitXPOrb", -1, -1, 10000).apply(GENERIC_KEY);
public static final ConfigInteger SCULK_SENSOR_PULSE_LENGTH = new ConfigInteger ("sculkSensorPulseLength", 40, 0, 10000).apply(GENERIC_KEY);
public static final ConfigFloat SERVER_DATA_SYNC_CACHE_TIMEOUT = new ConfigFloat ("serverDataSyncCacheTimeout", 1.0f, 0.25f, 5.0f).apply(GENERIC_KEY);
public static final ConfigInteger SERVER_NBT_REQUEST_RATE = new ConfigInteger ("serverNbtRequestRate", 2).apply(GENERIC_KEY);
public static final ConfigBoolean SHULKER_DISPLAY_BACKGROUND_COLOR = new ConfigBoolean ("shulkerDisplayBgColor", true).apply(GENERIC_KEY);
public static final ConfigBoolean SHULKER_DISPLAY_ENDER_CHEST = new ConfigBoolean ("shulkerDisplayEnderChest", false).apply(GENERIC_KEY);
public static final ConfigBoolean SHULKER_DISPLAY_REQUIRE_SHIFT = new ConfigBoolean ("shulkerDisplayRequireShift", true).apply(GENERIC_KEY);
public static final ConfigBoolean SLOT_SYNC_WORKAROUND = new ConfigBoolean ("slotSyncWorkaround", true).apply(GENERIC_KEY);
public static final ConfigBoolean SLOT_SYNC_WORKAROUND_ALWAYS = new ConfigBoolean ("slotSyncWorkaroundAlways", false).apply(GENERIC_KEY);
Expand Down Expand Up @@ -152,6 +147,7 @@ public static class Generic
POTION_WARNING_BENEFICIAL_ONLY,
REMEMBER_FLEXIBLE,
SHULKER_DISPLAY_BACKGROUND_COLOR,
SHULKER_DISPLAY_ENDER_CHEST,
SHULKER_DISPLAY_REQUIRE_SHIFT,
SLOT_SYNC_WORKAROUND,
SLOT_SYNC_WORKAROUND_ALWAYS,
Expand Down Expand Up @@ -212,6 +208,7 @@ public static class Generic
RENDER_LIMIT_ITEM,
RENDER_LIMIT_XP_ORB,
SCULK_SENSOR_PULSE_LENGTH,
SERVER_DATA_SYNC_CACHE_TIMEOUT,
SERVER_NBT_REQUEST_RATE,
SNAP_AIM_PITCH_STEP,
SNAP_AIM_THRESHOLD_PITCH,
Expand Down
85 changes: 55 additions & 30 deletions src/main/java/fi/dy/masa/tweakeroo/config/FeatureToggle.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ public enum FeatureToggle implements IHotkeyTogglable, IConfigNotifiable<IConfig
private final static String FEATURE_KEY = Reference.ID+ ".config.feature_toggle";

private final String name;
private final String comment;
private final String prettyName;
private final String translatedName;
private String comment;
private String prettyName;
private String translatedName;
private final IKeybind keybind;
private final boolean defaultValueBoolean;
private final boolean singlePlayer;
Expand Down Expand Up @@ -250,12 +250,11 @@ public String getName()
@Override
public String getConfigGuiDisplayName()
{
// This doesn't get called ?
String name = StringUtils.getTranslatedOrFallback(this.getTranslatedName(), this.getName());
String name = StringUtils.getTranslatedOrFallback(this.translatedName, this.name);

if (this.singlePlayer)
{
return GuiBase.TXT_GOLD + name + GuiBase.TXT_RST;
name = GuiBase.TXT_GOLD + name + GuiBase.TXT_RST;
}

return name;
Expand All @@ -265,63 +264,89 @@ public String getConfigGuiDisplayName()
public String getPrettyName()
{
return StringUtils.getTranslatedOrFallback(this.prettyName,
!this.prettyName.isEmpty() ? this.prettyName : StringUtils.splitCamelCase(this.name.substring(5)));
!this.prettyName.isEmpty() ? this.prettyName : StringUtils.splitCamelCase(this.name.substring(5)));
}

@Override
public String getStringValue()
public String getTranslatedName()
{
return String.valueOf(this.valueBoolean);
String name = StringUtils.getTranslatedOrFallback(this.translatedName, this.name);

if (this.singlePlayer)
{
name = GuiBase.TXT_GOLD + name + GuiBase.TXT_RST;
}

return name;
}

@Override
public String getDefaultStringValue()
public String getComment()
{
return String.valueOf(this.defaultValueBoolean);
String comment = StringUtils.getTranslatedOrFallback(this.comment, this.comment);

if (comment != null && this.singlePlayer)
{
return comment + "\n" + StringUtils.translate("tweakeroo.label.config_comment.single_player_only");
}

//System.out.printf("FeatureToggle#getComment(): comment [%s] // test [%s]\n", this.comment, comment);
return comment;
}

@Override
public void setValueFromString(String value)
public void setPrettyName(String s)
{
this.prettyName = s;
}

@Override
public void onValueChanged()
public void setTranslatedName(String s)
{
if (this.callback != null)
{
this.callback.onValueChanged(this);
}
this.translatedName = s;
}

@Override
public void setValueChangeCallback(IValueChangeCallback<IConfigBoolean> callback)
public void setComment(String s)
{
this.callback = callback;
this.comment = s;
}

private static String buildTranslateName(String name, String type)
{
return FEATURE_KEY + "." + type + "." + name;
}

@Override
public String getComment()
public String getStringValue()
{
String comment = StringUtils.getTranslatedOrFallback(this.comment, this.comment);
return String.valueOf(this.valueBoolean);
}

if (comment != null && this.singlePlayer)
{
return comment + "\n" + StringUtils.translate("tweakeroo.label.config_comment.single_player_only");
}
@Override
public String getDefaultStringValue()
{
return String.valueOf(this.defaultValueBoolean);
}

return comment;
@Override
public void setValueFromString(String value)
{
}

@Override
public String getTranslatedName()
public void onValueChanged()
{
return this.translatedName;
if (this.callback != null)
{
this.callback.onValueChanged(this);
}
}

private static String buildTranslateName(String name, String type)
@Override
public void setValueChangeCallback(IValueChangeCallback<IConfigBoolean> callback)
{
return FEATURE_KEY + "." + type + "." + name;
this.callback = callback;
}

@Override
Expand Down
27 changes: 20 additions & 7 deletions src/main/java/fi/dy/masa/tweakeroo/data/ServerDataSyncer.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;

import fi.dy.masa.malilib.interfaces.IClientTickHandler;
import fi.dy.masa.malilib.network.ClientPlayHandler;
import fi.dy.masa.malilib.network.IPluginClientPlayHandler;
import fi.dy.masa.malilib.util.Constants;
import fi.dy.masa.malilib.util.InventoryUtils;
import fi.dy.masa.malilib.util.NbtKeys;
import fi.dy.masa.malilib.util.WorldUtils;
import fi.dy.masa.malilib.util.nbt.NbtKeys;
import fi.dy.masa.tweakeroo.Reference;
import fi.dy.masa.tweakeroo.Tweakeroo;
import fi.dy.masa.tweakeroo.config.Configs;
Expand Down Expand Up @@ -69,7 +70,6 @@ public static ServerDataSyncer getInstance()
// Data Cache
private final ConcurrentHashMap<BlockPos, Pair<Long, Pair<BlockEntity, NbtCompound>>> blockEntityCache = new ConcurrentHashMap<>();
private final ConcurrentHashMap<Integer, Pair<Long, Pair<Entity, NbtCompound>>> entityCache = new ConcurrentHashMap<>();
private final long cacheTimeout = 4;
private long serverTickTime = 0;
// Requests to be executed
private final Set<BlockPos> pendingBlockEntitiesQueue = new LinkedHashSet<>();
Expand Down Expand Up @@ -195,7 +195,7 @@ public void reset(boolean isLogout)
else
{
Tweakeroo.printDebug("ServerDataSyncer#reset() - dimension change or log-in");
this.serverTickTime = System.currentTimeMillis() - (this.cacheTimeout + 5) * 1000L;
this.serverTickTime = System.currentTimeMillis() - (this.getCacheTimeout() + 5000L);
this.tickCache();
this.serverTickTime = System.currentTimeMillis();
this.clientWorld = mc.world;
Expand All @@ -207,11 +207,16 @@ public void reset(boolean isLogout)
this.pendingEntitiesQueue.clear();
}

private long getCacheTimeout()
{
return (long) (MathHelper.clamp(Configs.Generic.SERVER_DATA_SYNC_CACHE_TIMEOUT.getFloatValue(), 0.25f, 25.0f) * 1000L);
}

private void tickCache()
{
long nowTime = System.currentTimeMillis();
long blockTimeout = (this.cacheTimeout) * 1000L;
long entityTimeout = (this.cacheTimeout / 2) * 1000L;
long blockTimeout = this.getCacheTimeout();
long entityTimeout = this.getCacheTimeout() * 2;

synchronized (this.blockEntityCache)
{
Expand Down Expand Up @@ -414,7 +419,10 @@ else if (world.getBlockState(pos).getBlock() instanceof BlockEntityProvider)
NbtCompound nbt = be.createNbtWithIdentifyingData(world.getRegistryManager());
Pair<BlockEntity, NbtCompound> pair = Pair.of(be, nbt);

this.blockEntityCache.put(pos, Pair.of(System.currentTimeMillis(), pair));
synchronized (this.blockEntityCache)
{
this.blockEntityCache.put(pos, Pair.of(System.currentTimeMillis(), pair));
}

return pair;
}
Expand Down Expand Up @@ -443,7 +451,12 @@ else if (world.getBlockState(pos).getBlock() instanceof BlockEntityProvider)
if (entity != null && entity.saveSelfNbt(nbt))
{
Pair<Entity, NbtCompound> pair = Pair.of(entity, nbt);
this.entityCache.put(entityId, Pair.of(System.currentTimeMillis(), pair));

synchronized (this.entityCache)
{
this.entityCache.put(entityId, Pair.of(System.currentTimeMillis(), pair));
}

return pair;
}
}
Expand Down
Loading

0 comments on commit 1844453

Please sign in to comment.