Compare commits

..
6 Commits
Author SHA1 Message Date
Glease 7f19399ba3 Bump version 2021-09-08 22:08:59 +08:00
Glease 4982bb780d Add a debug check to sniff out errors like typos 2021-09-08 22:07:50 +08:00
DreamMasterXXL a069612e04 bump version 2021-08-16 14:11:01 +02:00
iouter ab09b791bd Update zh_CN.lang (#2)
* Add zh_CN.lang

* Update zh_CN.lang
2021-08-11 17:32:17 +08:00
Glease b086a65828 Fix typo in ofBlockUnlocalizedName
also added standard way of toggling debug mode pogrammatically
2021-08-01 03:07:51 +08:00
Glease f1f6dae00f Add generalized GT5's ofCoil 2021-07-22 12:08:24 +08:00
7 changed files with 123 additions and 8 deletions

No files matched your search

+1 -1
View File
@@ -1,5 +1,5 @@
modGroup = com.gtnewhorizon
modVersion = 1.0.7
modVersion = 1.0.10
modBaseName = StructureLib
forgeVersion = 1.7.10-10.13.4.1614-1.7.10
@@ -120,4 +120,12 @@ public class StructureLibAPI {
public static Item getItemBlockHint() {
return StructureLib.itemBlockHint;
}
public static boolean isDebugEnabled() {
return StructureLib.DEBUG_MODE;
}
public static void setDebugEnabled(boolean enabled) {
StructureLib.DEBUG_MODE = enabled;
}
}
@@ -13,8 +13,11 @@ public interface IStructureDefinition<T> {
/**
* Used internally
*
* Might, but is not required, to throw {@link java.util.NoSuchElementException} if the given structure piece is not found.
*
* @param name same name as for other methods here
* @return the array of elements to process
* @throws java.util.NoSuchElementException if the given structure piece is not found and the moon phase perfectly matches
*/
IStructureElement<T>[] getStructureFor(String name);
@@ -0,0 +1,12 @@
package com.gtnewhorizon.structurelib.structure;
import net.minecraft.block.Block;
/**
* a function to extract tier info from a block.
* @param <TIER>
*/
@FunctionalInterface
public interface ITierConverter<TIER> {
TIER convert(Block block, int meta);
}
@@ -193,6 +193,9 @@ public class StructureDefinition<T> implements IStructureDefinition<T> {
@Override
public IStructureElement<T>[] getStructureFor(String name) {
return structures.get(name);
IStructureElement<T>[] elements = structures.get(name);
if (elements == null)
throw new NoSuchElementException(name);
return elements;
}
}
@@ -13,7 +13,9 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
@@ -21,13 +23,16 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.IntBinaryOperator;
import java.util.function.Supplier;
import static java.lang.Integer.MIN_VALUE;
@@ -187,6 +192,81 @@ public class StructureUtility {
//region block
/**
* A more primitive variant of {@link #ofBlocksTiered(ITierConverter, List, Object, BiConsumer, Function)}
* Main difference is this one is check only.
* @see #ofBlocksTiered(ITierConverter, Object, BiConsumer, Function)
*/
public static <T, TIER> IStructureElementCheckOnly<T> ofBlocksTiered(ITierConverter<TIER> tierExtractor, @Nullable TIER notSet, BiConsumer<T, TIER> setter, Function<T, TIER> getter) {
if (tierExtractor == null) throw new IllegalArgumentException();
if (setter == null) throw new IllegalArgumentException();
if (getter == null) throw new IllegalArgumentException();
return (t, world, x, y, z) -> {
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
TIER tier = tierExtractor.convert(block, meta);
TIER current = getter.apply(t);
if (Objects.equals(notSet, current)) {
setter.accept(t, tier);
return true;
}
return Objects.equals(current, tier);
};
}
/**
* Element representing a component with different tiers. Player can use more blueprint to get hints denoting more
* advanced components.
*
* There is yet no TileEntity counter part of this utility. Feel free to submit a PR to add it.
* @param allKnownTiers All known tiers as of calling. Can be empty or null. No hint will be spawned if empty or null. Cannot have null elements.
* First element denotes the most primitive tier. Last element denotes the most advanced tier.
* If not all tiers are available at definition construction time, use {@link #lazy(Supplier)} or its overloads to delay a little bit.
* @param notSet The value returned from {@code getter} when there were no tier info found in T yet. Can be null.
* @param getter a function to retrieve the current tier from T
* @param setter a function to set the current tier into T
* @param tierExtractor a function to extract tier info from a block.
*/
public static <T, TIER> IStructureElement<T> ofBlocksTiered(ITierConverter<TIER> tierExtractor, @Nullable List<Pair<Block, Integer>> allKnownTiers, @Nullable TIER notSet, BiConsumer<T, TIER> setter, Function<T, TIER> getter) {
List<Pair<Block, Integer>> hints = allKnownTiers == null ? Collections.emptyList() : allKnownTiers;
if (hints.stream().anyMatch(Objects::isNull)) throw new IllegalArgumentException();
IStructureElementCheckOnly<T> check = ofBlocksTiered(tierExtractor, notSet, setter, getter);
return new IStructureElement<T>() {
@Override
public boolean check(T t, World world, int x, int y, int z) {
return check.check(t, world, x, y, z);
}
private Pair<Block, Integer> getHint(ItemStack trigger) {
return hints.get(Math.min(Math.max(trigger.stackSize, 1), hints.size()));
}
@Override
public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
Pair<Block, Integer> hint = getHint(trigger);
if (hint == null)
return false;
StructureLibAPI.hintParticle(world, x, y, z, hint.getKey(), hint.getValue());
return true;
}
@Override
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
Pair<Block, Integer> hint = getHint(trigger);
if (hint == null)
return false;
if (hint.getKey() instanceof ICustomBlockSetting) {
ICustomBlockSetting block = (ICustomBlockSetting) hint.getKey();
block.setBlock(world, x, y, z, hint.getValue());
} else {
world.setBlock(x, y, z, hint.getKey(), hint.getValue(), 2);
}
return true;
}
};
}
/**
* Denote a block using unlocalized names. This can be useful to get around mod loading order issues.
* <p>
@@ -209,7 +289,7 @@ public class StructureUtility {
@Override
public boolean check(T t, World world, int x, int y, int z) {
return world.getBlock(x, y, z) != getBlock() && world.getBlockMetadata(x, y, z) == meta;
return world.getBlock(x, y, z) == getBlock() && world.getBlockMetadata(x, y, z) == meta;
}
@Override
@@ -17,15 +17,15 @@ tile.structurelib.blockhint.15.name=提示方块:错误
item.structurelib.frontRotationTool.name=正面旋转扳手 (StructureLib)
item.structurelib.frontRotationTool.desc.0=可以旋转/翻转多方块主机
item.structurelib.frontRotationTool.desc.1=旋转/翻转多方块主机时,会
item.structurelib.frontRotationTool.desc.2=带动机器结构一起旋转/翻转。
item.structurelib.frontRotationTool.desc.1=多方块机器结构也需要跟随
item.structurelib.frontRotationTool.desc.2=多方块主机一起旋转/翻转。
item.structurelib.constructableTrigger.name=多方块机器蓝图 (StructureLib)
item.structurelib.constructableTrigger.name=多方块结构全息投影仪
item.structurelib.constructableTrigger.desc.0=可以显示多方块机器的结构
item.structurelib.constructableTrigger.desc.1=只能在多方块主机上使用,将会显示机器
item.structurelib.constructableTrigger.desc.2=结构的细节。 (译者注:请搭高使用)
item.structurelib.constructableTrigger.desc.3= (创造模式下潜行右键可以直接完成搭建)
item.structurelib.constructableTrigger.desc.4=手中蓝图数量会影响显示的机器等级/模式/类型
item.structurelib.constructableTrigger.desc.4=此物品堆叠数量会影响显示的机器等级/模式/类型
structurelib.blockhint.desc.0=帮助你搭建机器
structurelib.blockhint.0.name=提示方块:1号
@@ -49,4 +49,13 @@ structurelib.blockhint.14.name=提示方块:非空气
structurelib.blockhint.desc.4=确保这里不是空气方块。
structurelib.blockhint.15.name=提示方块:错误
structurelib.blockhint.desc.5=ERROR,你想要做什么?
itemGroup.structurelib=StructureLib
itemGroup.structurelib=StructureLib
structurelib.config.client=客户端-配置
structurelib.config.client.tooltip=修改此配置只会改变游戏中的显示效果,而不会改变实际工作模式。
structurelib.config.client.hologram=全息投影仪-配置
structurelib.config.client.hologram.tooltip=这将决定默认情况下,机器结构细节将如何被投影到世界中。
structurelib.config.client.hologram.maxCoexisting=最多可以同时存在的全息投影数量
structurelib.config.client.hologram.maxCoexisting.tooltip=这决定最多可以同时存在多少台机器的全息投影。一般一次使用全息投影仪右键生成的所有机器结构细节被视为一个全息投影。当同时存在多个全息投影,并超过此数量时,再次使用全息投影仪会移除旧有的全息投影。
structurelib.config.client.hologram.removeColliding=移除冲突的全息投影
structurelib.config.client.hologram.removeColliding.tooltip=当新的全息投影与已存在的全息投影冲突时,开启此选项时会移除已存在的全息投影。