Skip to content

Commit

Permalink
Add integration for FloodLights (#16)
Browse files Browse the repository at this point in the history
* Add integration for FloodLights

* Fix FloodLights typo

* Replace `isBlockContainer` check with forge's `hasTileEntity`
  • Loading branch information
DCNick3 authored Jan 16, 2025
1 parent 768c483 commit b7cc62d
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 5 deletions.
2 changes: 2 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ dependencies {
compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.7.18-GTNH:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:OpenComputers:1.11.4-GTNH:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:waila:1.8.2:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:FloodLights:1.4.5:dev") { transitive = false }

runtimeOnlyNonPublishable("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-521-GTNH:dev")
runtimeOnlyNonPublishable("com.github.GTNewHorizons:GT5-Unofficial:5.09.51.73:dev")
Expand All @@ -64,6 +65,7 @@ dependencies {
runtimeOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.7.18-GTNH:dev")
runtimeOnlyNonPublishable("com.github.GTNewHorizons:Hodgepodge:2.6.15:dev")
runtimeOnlyNonPublishable("com.github.GTNewHorizons:ForgeMultipart:1.6.2:dev")
runtimeOnlyNonPublishable("com.github.GTNewHorizons:FloodLights:1.4.5:dev")

compileOnly deobf("https://www.immibis.com/mcmoddl/files/immibis-microblocks-59.1.2.jar", "immibis-microblocks-59.1.2")
compileOnly deobf("https://www.immibis.com/mcmoddl/files/immibis-core-59.1.4.jar", "immibis-core-59.1.4")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public boolean tryConsumePower(ItemStack stack, World world, int x, int y, int z

try {
Block block = spec.getBlock();
if (block.isBlockContainer) {
if (block.hasTileEntity(spec.getBlockMeta())) {
euUsage *= TE_PENALTY;
}
} catch (Throwable e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public enum CopyableProperty {
TEXT,
ORIENTATION,
DELAY,
INVERTED,
COLOR,
ROTATION_STATE,
;

public static final ImmutableList<CopyableProperty> VALUES = ImmutableList.copyOf(values());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
import com.recursive_pineapple.matter_manipulator.common.utils.Mods;
import com.recursive_pineapple.matter_manipulator.common.utils.Mods.Names;

import de.keridos.floodlights.tileentity.TileEntityMetaFloodlight;
import de.keridos.floodlights.tileentity.TileEntitySmallFloodlight;
import gcewing.architecture.common.tile.TileArchitecture;
import ic2.api.tile.IWrenchable;
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import scala.tools.nsc.typechecker.MethodSynthesis.MethodSynth.Getter;
import scala.tools.nsc.typechecker.MethodSynthesis.MethodSynth.Setter;

public class BlockPropertyRegistry {

Expand Down Expand Up @@ -131,7 +131,7 @@ public static void getProperties(World world, int x, int y, int z, Map<String, B

properties.putAll(props);

if (block.isBlockContainer) {
if (block.hasTileEntity(world.getBlockMetadata(x, y, z))) {
TileEntity tile = world.getTileEntity(x, y, z);

if (tile != null) {
Expand All @@ -154,7 +154,7 @@ public static BlockProperty<?> getProperty(World world, int x, int y, int z, Str
BlockProperty<?> prop = props.get(name);
if (prop != null) return prop;

if (block.isBlockContainer) {
if (block.hasTileEntity(world.getBlockMetadata(x, y, z))) {
TileEntity tile = world.getTileEntity(x, y, z);

if (tile != null) {
Expand All @@ -176,6 +176,7 @@ public static void init() {
if (Mods.StorageDrawers.isModLoaded()) initStorageDrawers();
if (Mods.IndustrialCraft2.isModLoaded()) initIC2();
if (Mods.ArchitectureCraft.isModLoaded()) initArch();
if (Mods.FloodLights.isModLoaded()) initFloodLights();
}

// #region Vanilla
Expand Down Expand Up @@ -848,6 +849,131 @@ public void setValue(World world, int x, int y, int z, Orientation value) {

// #endregion

// #region FloodLights

private static void initFloodLights() {
registerTileEntityInterfaceProperty(TileEntityMetaFloodlight.class, new AbstractDirectionBlockProperty("facing") {

@Override
public ForgeDirection getValue(World world, int x, int y, int z) {
if (!(world.getTileEntity(x, y, z) instanceof TileEntityMetaFloodlight floodlight)) return UNKNOWN;

return floodlight.getOrientation();
}

@Override
public void setValue(World world, int x, int y, int z, ForgeDirection forgeDirection) {
// Do the same thing FloodLights do in `onBlockPlacedBy`
if (!(world.getTileEntity(x, y, z) instanceof TileEntityMetaFloodlight floodlight)) return;

floodlight.setOrientation(forgeDirection);

if (!(floodlight instanceof TileEntitySmallFloodlight)) {
// copy rotation info into metadata because FloodLights does it too
world.setBlockMetadataWithNotify(x, y, z, forgeDirection.ordinal(), 2);
} else {
// NB: small electric light does not use metadata for rotation
// instead, it uses it to discern normal/small floodlights
// so don't modify metadata, just update it
world.markBlockForUpdate(x, y, z);
}
}
});

registerTileEntityInterfaceProperty(TileEntityMetaFloodlight.class, new BooleanProperty() {

@Override
public String getName() {
return "inverted";
}

@Override
public boolean getBoolean(World world, int x, int y, int z) {
if (!(world.getTileEntity(x, y, z) instanceof TileEntityMetaFloodlight floodlight)) return false;

return floodlight.getInverted();
}

@Override
public void setBoolean(World world, int x, int y, int z, boolean value) {
if (!(world.getTileEntity(x, y, z) instanceof TileEntityMetaFloodlight floodlight)) return;

if (floodlight.getInverted() != value) {
floodlight.toggleInverted();
}
}
});

registerTileEntityInterfaceProperty(TileEntityMetaFloodlight.class, new IntegerProperty() {

@Override
public String getName() {
return "mode";
}

@Override
public int getInt(World world, int x, int y, int z) {
if (!(world.getTileEntity(x, y, z) instanceof TileEntityMetaFloodlight floodlight)) return 0;

return floodlight.getMode();
}

@Override
public void setInt(World world, int x, int y, int z, int value) {
if (!(world.getTileEntity(x, y, z) instanceof TileEntityMetaFloodlight floodlight)) return;

floodlight.setMode(value);
}
});

registerTileEntityInterfaceProperty(TileEntityMetaFloodlight.class, new IntegerProperty() {

@Override
public String getName() {
return "color";
}

@Override
public int getInt(World world, int x, int y, int z) {
if (!(world.getTileEntity(x, y, z) instanceof TileEntityMetaFloodlight floodlight)) return 0;

return floodlight.getColor();
}

@Override
public void setInt(World world, int x, int y, int z, int value) {
if (!(world.getTileEntity(x, y, z) instanceof TileEntityMetaFloodlight floodlight)) return;

floodlight.setColor(value);
}
});

registerTileEntityInterfaceProperty(TileEntitySmallFloodlight.class, new BooleanProperty() {

@Override
public String getName() {
return "rotation_state";
}

@Override
public boolean getBoolean(World world, int x, int y, int z) {
if (!(world.getTileEntity(x, y, z) instanceof TileEntitySmallFloodlight floodlight)) return false;

return floodlight.getRotationState();
}

@Override
public void setBoolean(World world, int x, int y, int z, boolean value) {
if (!(world.getTileEntity(x, y, z) instanceof TileEntitySmallFloodlight floodlight)) return;

floodlight.setRotationState(value);
world.markBlockForUpdate(x, y, z);
}
});
}

// #endregion

public static DirectionBlockProperty methodIntDirectionTile(Class<?> clazz, String getterName, String setterName) {
try {
Method getter = clazz.getDeclaredMethod(getterName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum Mods {
ForgeMicroblocks(Names.FORGE_MICROBLOCKS),
/** The forge multipart library. */
ForgeMultipart(Names.FORGE_MULTIPART),
FloodLights(Names.FLOOD_LIGHTS),
GregTech(Names.GREG_TECH),
GTPlusPlus(Names.G_T_PLUS_PLUS),
GraviSuite(Names.GRAVI_SUITE),
Expand Down Expand Up @@ -51,6 +52,7 @@ public static class Names {
public static final String ENDER_I_O = "EnderIO";
public static final String FORGE_MICROBLOCKS = "ForgeMicroblock";
public static final String FORGE_MULTIPART = "ForgeMultipart";
public static final String FLOOD_LIGHTS = "FloodLights";
public static final String GREG_TECH = "gregtech";
public static final String GRAVI_SUITE = "GraviSuite";
public static final String G_T_PLUS_PLUS = "miscutils";
Expand Down

0 comments on commit b7cc62d

Please sign in to comment.