Immersive Engineering

Immersive Engineering

134M Downloads

Not able to use method setEnabled() with Diesel Generator in CC: Tweaked (ComputerCraft)

pespinho opened this issue ยท 2 comments

commented

Minecraft Version

1.18

Immersive Engineering Version

8.1.0-150

Expected Behavior

The expected behavior would be to be able enable or disable the Diesel Generator through a lua script in ComputerCraft after wrapping it as a peripheral:

lua> g = peripheral.wrap("diesel_generator_0")
lua> g.setEnabled(true) -- Enables generator.
lua> g.setEnabled(false) -- Disables generator.
lua>

Actual Behavior

When using the method, an exception is thrown instead:

lua> g = peripheral.wrap("diesel_generator_0")
lua> g.setEnabled(true) -- Enables generator.
lua> g.setEnabled(false) -- Disables generator.
lua:1: class blusunrize.immersiveengineering.common.blocks.metal.DieselGeneratorBlockEntity cannot be cast to class blusunrize.immersiveengineering.common.blocks.generic.PoweredMultiblockBlockEntity (blusunrize.immersiveengineering.common.blocks.metal.DieselGeneratorBlockEntity and blusunrize.immersiveengineering.common.blocks.generic.PowerdMultiblockBlockEntity are in module immersiveengineering@1.18.2-8.1.0-150 of loader 'TRANSFORMER' @15c6027d)
lua> 

Bildschirmfoto 2022-08-06 um 09 43 09

Steps to reproduce

  1. Connect a Computer from CC: Tweaked to the Redstone interface of a diesel generator using two wired modems networking cable
  2. Certify that both devices are in the network. Both modems shows red "ring".
  3. Right click computer to open the interface.
  4. Open the Lua interactive shell, by typing lua and pressing [ENTER].
  5. Wrap the diesel as a peripheral using the peripheral.wrap() method of CC: Tweaked as seen above and use the setEnabled()method.
  6. Exception is thrown.

Debug Crash Log

https://pastebin.com/cRDvjbgD

commented

My theory is that the problem could be in:

ImmersiveEngineering/src/main/java/blusunrize/immersiveengineering/common/util/compat/computers/generic/impl/MultiblockCallbacks.java

because setEnabled() expects the parameter env to have a type of CallbackEnvironment<PoweredMultiblockBlockEntity<?, ?>> and the diesel generator isn't a "Powered Multiblock Entity".

I also see that DieselGeneratorBlockEntity extends MultiblockPartBlockEntity<DieselGeneratorBlockEntity> and the MultiblockPartBlockEntity<T> has the field:

public final ComputerControlState computerControl = new ComputerControlState();

This field is used in the setEnabled() method.

So in theory, this could work if setEnabled() would expect the env variable to be of type CallbackEnvironment< MultiblockPartBlockEntity <?>> instead.

commented

I also see the the method isRunning() triggers the same exception and my theory would also apply to it.