mrh0 / createaddition

Create Crafts & Additions, Addon to the Create mod by the Create Team.
Other
83 stars 110 forks source link

Tesla Coil FE charging. [FABRIC] #356

Closed michlbro closed 1 year ago

michlbro commented 1 year ago

I was just wondering if FE charging works on the fabric port. I am currently trying to charge a jetpack (Iron Jetpacks ported over to fabric.) using a tesla coil, but it isn't working (The tesla coil does cause damage to the player, so I assume it works?). https://github.com/shedaniel/IronJetpacks/issues/27#issue-1419426821

michlbro commented 1 year ago

Ok, so the iron jetpack mod uses Tech Reborn Energy and not Forge Energy. Since it's fabric, I assume most other mods will use Tech Reborn Energy (https://github.com/shedaniel/IronJetpacks/issues/27#issuecomment-1287871941). If possible, could we get support for Tech Reborn Energy in the fabric port?

Edit: Just tested that the alternator is pretty much useless in fabric since it generates FE energy which cannot or (Hardly works -sometimes gives energy) with another mod (Industrial Revolution).

Pultex commented 1 year ago

yeah was hoping for RF gnereation as FE is a api in forge and Fabric does not have that

seems odd to make a fabric port that does work in most aspects with no energy system that works

Pultex commented 1 year ago

well maybe the answer is in #321 no support here for fabric

snoandpetals commented 1 year ago

Create Additions does use Tech Reborn energy, as you can use the Alternator to power Tech Reborn items, however, the Tesla coil is broken in the Fabric port.

I've been told by a Fabric contributor that the offending line may be below, as the function returns a READ ONLY version of the energy storage, meaning the Tesla Coil can read the energy of the item, but can't write to it. https://github.com/mrh0/createaddition/blob/3d286f476e325a08f4bfee645f4649c8fe3b79ac/src/main/java/com/mrh0/createaddition/blocks/tesla_coil/TeslaCoilTileEntity.java#L170

michlbro commented 1 year ago

Thanks for looking into it. I am no expert in java (Trying to learn more about it, but it looks so awful compared to any other language) but I’ll see what I can do. Tech Reborn is kind of finicky to work with in create additions, as in you must have the alternators right next to a lazuli flux container (battery block) as a pump to get energy into the cables since it wont push energy straight into them from the alternators for some reason or the cables will be stuck at a set amount. Sometimes the electric motors will consume energy whilst it’s not even running. I am only experiencing these bugs with Industrial Revolution and it’s hard to reproduce these bugs.

Sewdohe commented 1 year ago

Thanks for looking into it. I am no expert in java (Trying to learn more about it, but it looks so awful compared to any other language) but I’ll see what I can do. Tech Reborn is kind of finicky to work with in create additions, as in you must have the alternators right next to a lazuli flux container (battery block) as a pump to get energy into the cables since it wont push energy straight into them from the alternators for some reason or the cables will be stuck at a set amount. Sometimes the electric motors will consume energy whilst it’s not even running. I am only experiencing these bugs with Industrial Revolution and it’s hard to reproduce these bugs.

I just got builds going for the mod yesterday, I'm going to poke around the fabric branch too and see if I can make something shake and bake. I'd love to see this mod back to parity with it's Forge counterpart.

Sewdohe commented 1 year ago

So I've tried working on the problematic line, with no luck. No matter what I try it just won't transfer energy into the receiving block. Upon closer inspection though, if you hook a battery to the Tesla coil you can see the battery discharge as expected. I've switched from using withInital to using ofSingleSlot as such:

    protected boolean chargeStack(ItemStack stack, TransportedItemStack transported, TransportedItemStackHandlerBehaviour handler) {
        ContainerItemContext ctx = ContainerItemContext.withInitial(stack); // get stack context (not mutable)
        ContainerItemContext ctx_slot = ContainerItemContext.ofSingleSlot(ctx.getMainSlot()); // get singleSlotContext of stack (mutable?)
        EnergyStorage es = ctx_slot.find(EnergyStorage.ITEM); // get energyStorage

        long amountToUse = Math.min(getConsumption(), energy.getAmount()); // amount of energy to consume

        if (EnergyStorageUtil.isEnergyStorage(stack)) { // make sure the targeted stack is energy storage
            if(energy.getAmount() < stack.getCount())
                return false;
            try (Transaction t = TransferUtil.getTransaction()) {
                energy.internalConsumeEnergy(es.insert(amountToUse, t)); // take energy from source and place into destination
                t.commit(); // commit transaction
            }
            return true;
        } else {
            return false;
        }
    }

no dice.

snoandpetals commented 1 year ago

https://github.com/mrh0/createaddition/pull/468 This PR fixes Tesla FE transfer. Thank you FluffyBumblebees, and all who tried.