Skip to content

Commit f4beff7

Browse files
committed
Minor cleanup
Signed-off-by: roadhog360 <[email protected]>
1 parent cd72b2e commit f4beff7

14 files changed

Lines changed: 111 additions & 85 deletions

File tree

dependencies.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ dependencies {
5757
compileOnly('curse.maven:hardcore-ender-expansion-228015:2316923')
5858

5959
compileOnly('org.jetbrains:annotations:24.0.1')
60-
compileOnly("org.projectlombok:lombok:1.18.36") { transitive = false }
61-
annotationProcessor("org.projectlombok:lombok:1.18.36")
60+
compileOnly("org.projectlombok:lombok:1.18.42") { transitive = false }
61+
annotationProcessor("org.projectlombok:lombok:1.18.42")
6262
}

src/main/java/roadhog360/hogutils/api/blocksanditems/block/BaseFlower.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import java.util.List;
1717
import java.util.Map;
1818

19-
public abstract class BaseFlower extends BlockFlower implements ISubtypesBlock {
19+
public abstract class BaseFlower extends BlockFlower implements ISubtypesBlock, IPotableData {
2020

2121
/// This CANNOT be an array, NotEnoughIDs has NEGATIVE metas, so we need this instead.
2222
private final Map<Integer, IIcon> icons = new Int2ObjectArrayMap<>();
@@ -118,4 +118,9 @@ public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) {
118118
}
119119
}
120120
}
121+
122+
@Override
123+
public boolean isPotable(int meta) {
124+
return isMetadataEnabled(meta);
125+
}
121126
}

src/main/java/roadhog360/hogutils/api/blocksanditems/block/ICustomActivateSound.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public interface ICustomActivateSound {
2525
/// @param z
2626
/// @param prevSound The previous sound that you are overriding
2727
/// @return The suffix to add to {@link ICustomActivateSound#getSound(World, int, int, int, String)}.
28-
/// Don't forget to add the dot at the start! (This is mandatory in case you have a setup where you don't want the dot for some reason)
28+
/// Don't forget to add the dot at the start!
29+
/// Adding the dot yourself is mandatory in case you have a setup where you don't want the dot for some reason.
2930
@NonNull
3031
default String getSuffix(World world, int x, int y, int z, String prevSound) {
3132
if (prevSound.contains("random.door") || prevSound.contains("random.chest")) {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package roadhog360.hogutils.api.blocksanditems.block;
2+
3+
/// Is this Block potable?
4+
public interface IPotableData {
5+
boolean isPotable(int meta);
6+
}

src/main/java/roadhog360/hogutils/api/blocksanditems/block/itemblock/BaseItemBlockPotable.java

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package roadhog360.hogutils.api.blocksanditems.utils;
2+
3+
import net.minecraft.util.IIcon;
4+
import org.jetbrains.annotations.ApiStatus;
5+
import org.jetbrains.annotations.Nullable;
6+
7+
@ApiStatus.NonExtendable
8+
public class MetaVariant {
9+
public static int NO_OVERRIDE = -2;
10+
11+
@Nullable
12+
protected String displayName;
13+
@Nullable
14+
protected String iconName;
15+
@Nullable
16+
protected IIcon icon;
17+
18+
public MetaVariant(@Nullable String name) {
19+
this(name, name);
20+
}
21+
22+
public MetaVariant(@Nullable String displayName, @Nullable String iconName) {
23+
this.displayName = displayName;
24+
this.iconName = iconName;
25+
}
26+
27+
public @Nullable String getDisplayName() {
28+
return displayName;
29+
}
30+
31+
public @Nullable String getIconName() {
32+
return iconName;
33+
}
34+
35+
public @Nullable IIcon getIcon() {
36+
return icon;
37+
}
38+
39+
public void setIcon(IIcon icon) {
40+
this.icon = icon;
41+
}
42+
}

src/main/java/roadhog360/hogutils/api/blocksanditems/utils/RegistryEntryBlock.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66
import net.minecraft.item.Item;
77
import net.minecraft.item.ItemBlock;
88
import org.jetbrains.annotations.Nullable;
9-
import roadhog360.hogutils.api.blocksanditems.block.*;
10-
import roadhog360.hogutils.api.blocksanditems.block.itemblock.*;
9+
import roadhog360.hogutils.api.blocksanditems.block.BaseDoor;
10+
import roadhog360.hogutils.api.blocksanditems.block.BaseLeaves;
11+
import roadhog360.hogutils.api.blocksanditems.block.BaseSlab;
12+
import roadhog360.hogutils.api.blocksanditems.block.ISubtypesBlock;
13+
import roadhog360.hogutils.api.blocksanditems.block.itemblock.BaseDoorItemBlock;
14+
import roadhog360.hogutils.api.blocksanditems.block.itemblock.BaseItemBlock;
15+
import roadhog360.hogutils.api.blocksanditems.block.itemblock.BaseLeavesItemBlock;
16+
import roadhog360.hogutils.api.blocksanditems.block.itemblock.BaseSlabItemBlock;
1117
import roadhog360.hogutils.api.blocksanditems.utils.base.RegistryEntry;
1218

1319
public class RegistryEntryBlock extends RegistryEntry<Block> {
@@ -21,7 +27,7 @@ public class RegistryEntryBlock extends RegistryEntry<Block> {
2127

2228
public RegistryEntryBlock(String name, boolean isEnabled, Block block) {
2329
super(name, isEnabled, block);
24-
this.itemBlockClass = guessItemBlock(block);
30+
this.itemBlockClass = getItemBlock(block);
2531
this.itemBlockCtorArgs = new Object[0];
2632
}
2733

@@ -34,16 +40,15 @@ public RegistryEntryBlock(String name, boolean isEnabled, Block block,
3440
@Nullable Class<? extends ItemBlock> itemBlockClass, @Nullable Object... itemBlockCtorArgs) {
3541
super(name, isEnabled, block);
3642
this.itemBlockClass = itemBlockClass;
37-
this.itemBlockCtorArgs = itemBlockCtorArgs;
43+
this.itemBlockCtorArgs = itemBlockCtorArgs == null ? new Object[0] : itemBlockCtorArgs;
3844
}
3945

4046
/// Used when no ItemBlock is passed; we guess what it should get.
4147
/// This is used for convenience so every single block with sub blocks doesn't need to declare that;
4248
/// only special ItemBlocks that don't fit this criteria or no (null) ItemBlocks should need deliberate declaration.
43-
protected Class<? extends ItemBlock> guessItemBlock(Block block) {
49+
protected Class<? extends ItemBlock> getItemBlock(Block block) {
4450
return block instanceof BaseSlab ? BaseSlabItemBlock.class
4551
: block instanceof BaseDoor ? BaseDoorItemBlock.class
46-
: block instanceof BaseFlower ? BaseItemBlockPotable.class
4752
: block instanceof BaseLeaves ? BaseLeavesItemBlock.class
4853
: block instanceof ISubtypesBlock ? BaseItemBlock.class
4954
: ItemBlock.class;
@@ -60,11 +65,7 @@ public Item getItemBlock() {
6065
@Override
6166
protected void doRegistration() {
6267
if (hasItemBlock()) { // If this block has an ItemBlock, check whether it should be registered with constructor args
63-
if(itemBlockCtorArgs != null) {
64-
GameRegistry.registerBlock(object, itemBlockClass, name.toLowerCase(), itemBlockCtorArgs);
65-
} else {
66-
GameRegistry.registerBlock(object, itemBlockClass, name.toLowerCase());
67-
}
68+
GameRegistry.registerBlock(object, itemBlockClass, name.toLowerCase(), itemBlockCtorArgs);
6869
} else {
6970
GameRegistry.registerBlock(object, null, name.toLowerCase());
7071
}

src/main/java/roadhog360/hogutils/api/blocksanditems/utils/base/RegistryEntry.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package roadhog360.hogutils.api.blocksanditems.utils.base;
22

33
import roadhog360.hogutils.api.blocksanditems.IReferenceBase;
4+
import roadhog360.hogutils.api.utils.GenericUtils;
45

56
import java.util.Collection;
67

@@ -35,13 +36,13 @@ public void register() {
3536
protected abstract void doRegistration();
3637

3738
/// Enforce lower alphanumeric with underscores and slashes
38-
/// I do the lowercasing automatically but I check anyways in case this function is called from a custom class
39+
/// I do the lowercasing automatically, but I check anyway in case this function is called from a custom class
3940
protected void checkName(String name) {
40-
if (!name.matches("^[a-z0-9_/]*$")) {
41+
if (!GenericUtils.isLowerAlphaNumeric(name)) {
4142
throw new IllegalArgumentException(
4243
"Don't register a non-alphanumeric name! Just because you can doesn't mean you should!" +
4344
"Forge should prevent this, so I'm doing their work for them..." +
44-
"If you want to use my helper tools, alphanumeric ONLY with underscores (_) and forward slashes! (/)"
45+
"If you want to use my helper tools, names that alphanumeric ONLY with underscores (_) and forward slashes (/) are allowed!"
4546
);
4647
}
4748
}

src/main/java/roadhog360/hogutils/api/hogtags/helpers/MiscHelpers.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,13 @@ public static void enforceTagsSpec(String... tags) {
8080

8181
/// Ensures the spec of tags is enforced, and checks the passed in tags for compliance.
8282
/// If the following spec is not met, the game will throw an {@link IllegalArgumentException}.
83-
/// - Must have a properly namespaced ID. For example, `examplemod:example` is correct, but `examplemod` isn't.
83+
/// - Must have a properly namespaced ID. For example, `examplemod:example` is correct, but `example` isn't.
8484
/// - `#` is purely for display purposes and tags in the registry do not have it.
85+
/// - Must not contain any characters disallowed by the Windows filesystem. (except for `:`, and `/`)
8586
/// If these conditions are not met, the game will throw an {@link IllegalArgumentException}.
8687
public static void enforceTagSpec(String tag) {
87-
if (tag == null || tag.isEmpty() || tag.equals("#") || tag.equals(":") || tag.equals("#:")) {
88-
throw new IllegalArgumentException("Cannot pass in empty tag (or just \"#\") to the tags registry!");
89-
}
90-
if (!GenericUtils.verifyFilenameIntegrity(tag, ALLOWED_CHARS)) {
91-
throw new IllegalArgumentException("Cannot instantiate tag with disallowed characters from Windows filesystem! Received [" + tag + "]");
88+
if (tag == null || tag.isEmpty()) {
89+
throw new IllegalArgumentException("Cannot pass in empty tag to the tags registry!");
9290
}
9391
if (tag.startsWith("#")) {
9492
throw new IllegalArgumentException("Tag should not start with #; the # is for display purposes only and doesn't \"exist\". Received [" + tag + "]");

src/main/java/roadhog360/hogutils/api/utils/GenericUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ public static boolean verifyFilenameIntegrity(@NonNull String string, char @Null
220220
return true;
221221
}
222222

223+
public static boolean isLowerAlphaNumeric(String name) {
224+
return name.matches("^[a-z0-9_/]*$");
225+
}
226+
223227
public static class Constants {
224228
public static final float[][] COLORS_RGB = EntitySheep.fleeceColorTable;
225229

0 commit comments

Comments
 (0)