mirror of
https://github.com/GTNewHorizons/StructureLib.git
synced 2026-11-18 11:19:29 +00:00
configurable autoplace
This commit is contained in:
7 files changed
+61
-44
No files matched your search
@@ -15,6 +15,8 @@ public enum ConfigurationHandler {
|
||||
private Configuration config;
|
||||
private int maxCoexistingHologram;
|
||||
private boolean removeCollidingHologram;
|
||||
private int autoPlaceBudget;
|
||||
private int autoPlaceInterval;
|
||||
|
||||
ConfigurationHandler() {
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
@@ -50,6 +52,25 @@ public enum ConfigurationHandler {
|
||||
"client.hologram",
|
||||
true,
|
||||
"An attempt will be made to remove an existing hologram if it collides with a new hologram.");
|
||||
autoPlaceBudget = config.getInt(
|
||||
"autoPlaceBudget",
|
||||
"common.hologram",
|
||||
25,
|
||||
1,
|
||||
200,
|
||||
"Max number of elements can be placed in one round of auto place.\n"
|
||||
+ "As expected, server side settings will overrides client settings.\n"
|
||||
+ "Certain larger multi might increase these values beyond this configured value.");
|
||||
autoPlaceInterval = config.getInt(
|
||||
"autoPlaceInterval",
|
||||
"common.hologram",
|
||||
300,
|
||||
0,
|
||||
20000,
|
||||
"Unit: milisecond. Minimal interval between two auto place round.\n"
|
||||
+ "As expected, server side settings will overrides client settings.\n"
|
||||
+ "Note this relates to the wall clock, not in game ticks.\n"
|
||||
+ "Value smaller than default is likely to be perceived as no minimal interval whatsoever.");
|
||||
|
||||
if (config.hasChanged()) {
|
||||
config.save();
|
||||
@@ -71,6 +92,14 @@ public enum ConfigurationHandler {
|
||||
return removeCollidingHologram;
|
||||
}
|
||||
|
||||
public int getAutoPlaceBudget() {
|
||||
return autoPlaceBudget;
|
||||
}
|
||||
|
||||
public int getAutoPlaceInterval() {
|
||||
return autoPlaceInterval;
|
||||
}
|
||||
|
||||
Configuration getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
+4
-6
@@ -1,20 +1,18 @@
|
||||
package com.gtnewhorizon.structurelib.alignment.constructable;
|
||||
|
||||
import static com.gtnewhorizon.structurelib.util.MiscUtils.getTagKeys;
|
||||
import static net.minecraftforge.common.util.Constants.NBT.TAG_COMPOUND;
|
||||
|
||||
import com.gtnewhorizon.structurelib.StructureLib;
|
||||
import java.util.Locale;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.gtnewhorizon.structurelib.StructureLib;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.Constants.NBT;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
|
||||
|
||||
import static com.gtnewhorizon.structurelib.util.MiscUtils.getTagKeys;
|
||||
import static net.minecraftforge.common.util.Constants.NBT.TAG_COMPOUND;
|
||||
|
||||
public class ChannelDataAccessor {
|
||||
private static final String SECONDARY_HINT_TAG = "channels";
|
||||
|
||||
|
||||
+26
-17
@@ -1,14 +1,15 @@
|
||||
package com.gtnewhorizon.structurelib.alignment.constructable;
|
||||
|
||||
import com.gtnewhorizon.structurelib.ConfigurationHandler;
|
||||
import com.gtnewhorizon.structurelib.StructureLib;
|
||||
import com.gtnewhorizon.structurelib.StructureLibAPI;
|
||||
import com.gtnewhorizon.structurelib.alignment.IAlignment;
|
||||
import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing;
|
||||
import com.gtnewhorizon.structurelib.structure.IItemSource;
|
||||
import java.util.WeakHashMap;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.world.World;
|
||||
@@ -17,9 +18,8 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class ConstructableUtility {
|
||||
|
||||
// TODO make these configurable and expose this to external world
|
||||
public static final int COOLDOWN = 5;
|
||||
private static final int BUDGET = 25;
|
||||
private static final WeakHashMap<EntityPlayerMP, Long> lastUse = new WeakHashMap<>();
|
||||
private static long clientSideLastUse = 0;
|
||||
|
||||
private ConstructableUtility() {}
|
||||
|
||||
@@ -41,10 +41,11 @@ public class ConstructableUtility {
|
||||
// not sneaking - client side will generate hologram. nothing to do on server side
|
||||
if (!aPlayer.isSneaking()) return true;
|
||||
|
||||
long timePast = StructureLib.getOverworldTime() - getLastUseTick(aStack);
|
||||
if (timePast < COOLDOWN) {
|
||||
long timePast = System.currentTimeMillis() - getLastUseMilis(aPlayer);
|
||||
if (timePast < ConfigurationHandler.INSTANCE.getAutoPlaceInterval()) {
|
||||
aPlayer.addChatComponentMessage(new ChatComponentTranslation(
|
||||
"item.structurelib.constructableTrigger.too_fast", COOLDOWN - timePast));
|
||||
"item.structurelib.constructableTrigger.too_fast",
|
||||
ConfigurationHandler.INSTANCE.getAutoPlaceInterval() - timePast));
|
||||
return true;
|
||||
}
|
||||
} else if (!StructureLib.isCurrentPlayer(aPlayer)) {
|
||||
@@ -74,13 +75,17 @@ public class ConstructableUtility {
|
||||
constructable.construct(aStack, false);
|
||||
} else if (constructable instanceof ISurvivalConstructable) {
|
||||
int built = ((ISurvivalConstructable) constructable)
|
||||
.survivalConstruct(aStack, BUDGET, IItemSource.fromPlayer(playerMP), playerMP);
|
||||
.survivalConstruct(
|
||||
aStack,
|
||||
ConfigurationHandler.INSTANCE.getAutoPlaceBudget(),
|
||||
IItemSource.fromPlayer(playerMP),
|
||||
playerMP);
|
||||
if (built > 0) {
|
||||
playerMP.addChatMessage(new ChatComponentTranslation("structurelib.autoplace.built_stat", built));
|
||||
} else if (built == -1) {
|
||||
playerMP.addChatMessage(new ChatComponentTranslation("structurelib.autoplace.complete"));
|
||||
}
|
||||
setLastUseTickToStackTag(aStack);
|
||||
setLastUseMilis(aPlayer);
|
||||
} else {
|
||||
playerMP.addChatMessage(new ChatComponentTranslation("structurelib.autoplace.error.not_enabled"));
|
||||
}
|
||||
@@ -89,19 +94,23 @@ public class ConstructableUtility {
|
||||
// client side
|
||||
// particles and text
|
||||
constructable.construct(aStack, true);
|
||||
if (getLastUseTick(aStack) == 0)
|
||||
if (System.currentTimeMillis() - getLastUseMilis(aPlayer) >= 300)
|
||||
StructureLib.addClientSideChatMessages(constructable.getStructureDescription(aStack));
|
||||
setLastUseMilis(aPlayer);
|
||||
return false;
|
||||
}
|
||||
|
||||
private static long getLastUseTick(ItemStack aStack) {
|
||||
return aStack.hasTagCompound() ? aStack.getTagCompound().getLong("LastUse") : 0;
|
||||
private static void setLastUseMilis(EntityPlayer aPlayer) {
|
||||
if (!(aPlayer instanceof EntityPlayerMP))
|
||||
// assume client side
|
||||
clientSideLastUse = System.currentTimeMillis();
|
||||
else lastUse.put((EntityPlayerMP) aPlayer, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
private static void setLastUseTickToStackTag(ItemStack aStack) {
|
||||
NBTTagCompound tag = aStack.stackTagCompound;
|
||||
if (tag == null) tag = aStack.stackTagCompound = new NBTTagCompound();
|
||||
// here we force use the overworld tick time, in case the current world is over
|
||||
tag.setLong("LastUse", StructureLib.getOverworldTime());
|
||||
private static long getLastUseMilis(EntityPlayer aPlayer) {
|
||||
if (!(aPlayer instanceof EntityPlayerMP))
|
||||
// assume client side
|
||||
return clientSideLastUse;
|
||||
return lastUse.getOrDefault(aPlayer, 0L);
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,9 @@ import com.gtnewhorizon.structurelib.StructureLib;
|
||||
import com.gtnewhorizon.structurelib.alignment.constructable.ChannelDataAccessor;
|
||||
import com.gtnewhorizon.structurelib.alignment.constructable.ConstructableUtility;
|
||||
import java.util.List;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
@@ -75,20 +73,4 @@ public class ItemConstructableTrigger extends Item {
|
||||
aList.add(translateToLocal("item.structurelib.constructableTrigger.desc.5"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(
|
||||
ItemStack p_77663_1_, World p_77663_2_, Entity p_77663_3_, int p_77663_4_, boolean p_77663_5_) {
|
||||
// remove LastUse tags if it times out,
|
||||
// so it can stack with other trigger item stacks
|
||||
// don't remove it too soon though, to prevent chat spam
|
||||
// this might be perceived as a hack, but ok this is simple enough to implement
|
||||
if (p_77663_1_.hasTagCompound()
|
||||
&& p_77663_1_.getTagCompound().getLong("LastUse") + ConstructableUtility.COOLDOWN * 2
|
||||
< StructureLib.getOverworldTime()) {
|
||||
NBTTagCompound tag = p_77663_1_.getTagCompound();
|
||||
tag.removeTag("LastUse");
|
||||
if (tag.hasNoTags()) p_77663_1_.setTagCompound(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
-1
@@ -1,7 +1,6 @@
|
||||
package com.gtnewhorizon.structurelib.structure;
|
||||
|
||||
import com.gtnewhorizon.structurelib.StructureLibAPI;
|
||||
import com.gtnewhorizon.structurelib.alignment.constructable.ConstructableUtility;
|
||||
import com.gtnewhorizon.structurelib.structure.IStructureElement.PlaceResult;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
Reference in new issue
Block a user