-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix CC compat on forge 2: Electric Boogaloo
- Loading branch information
Showing
8 changed files
with
172 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 24 additions & 13 deletions
37
...va/dev/ithundxr/createnumismatics/compat/computercraft/fabric/ComputerCraftProxyImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,40 @@ | ||
/* | ||
* Numismatics | ||
* Copyright (c) 2024 The Railways Team | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.ithundxr.createnumismatics.compat.computercraft.fabric; | ||
|
||
import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; | ||
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity; | ||
import dan200.computercraft.api.peripheral.PeripheralLookup; | ||
import dev.ithundxr.createnumismatics.compat.computercraft.ComputerCraftProxy; | ||
import dev.ithundxr.createnumismatics.compat.computercraft.implementation.ComputerBehaviour; | ||
|
||
import java.util.function.Function; | ||
|
||
import static dev.ithundxr.createnumismatics.compat.computercraft.ComputerCraftProxy.fallbackFactory; | ||
import static dev.ithundxr.createnumismatics.compat.computercraft.implementation.ComputerBehaviour.peripheralProvider; | ||
|
||
public class ComputerCraftProxyImpl { | ||
|
||
public static Function<SmartBlockEntity, ? extends AbstractComputerBehaviour> computerFactory; | ||
|
||
public static void registerWithDependency() { | ||
/* Comment if computercraft.implementation is not in the source set */ | ||
computerFactory = ComputerBehaviour::new; | ||
ComputerCraftProxy.computerFactory = ComputerBehaviour::new; | ||
|
||
PeripheralLookup.get().registerFallback((level, blockPos, blockState, blockEntity, direction) -> peripheralProvider(level, blockPos)); | ||
PeripheralLookup.get().registerFallback((level, blockPos, blockState, blockEntity, direction) -> ComputerBehaviour.peripheralProvider(level, blockPos)); | ||
} | ||
|
||
public static AbstractComputerBehaviour behaviour(SmartBlockEntity sbe) { | ||
if (computerFactory == null) | ||
return fallbackFactory.apply(sbe); | ||
return computerFactory.apply(sbe); | ||
if (ComputerCraftProxy.computerFactory == null) | ||
return ComputerCraftProxy.fallbackFactory.apply(sbe); | ||
return ComputerCraftProxy.computerFactory.apply(sbe); | ||
} | ||
} |
35 changes: 23 additions & 12 deletions
35
...ava/dev/ithundxr/createnumismatics/compat/computercraft/forge/ComputerCraftProxyImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,36 @@ | ||
/* | ||
* Numismatics | ||
* Copyright (c) 2024 The Railways Team | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.ithundxr.createnumismatics.compat.computercraft.forge; | ||
|
||
import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; | ||
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity; | ||
import dev.ithundxr.createnumismatics.compat.computercraft.ComputerCraftProxy; | ||
import dev.ithundxr.createnumismatics.compat.computercraft.implementation.ComputerBehaviour; | ||
|
||
import java.util.function.Function; | ||
|
||
import static dev.ithundxr.createnumismatics.compat.computercraft.ComputerCraftProxy.fallbackFactory; | ||
import static dev.ithundxr.createnumismatics.compat.computercraft.implementation.ComputerBehaviour.peripheralProvider; | ||
|
||
public class ComputerCraftProxyImpl { | ||
|
||
public static Function<SmartBlockEntity, ? extends AbstractComputerBehaviour> computerFactory; | ||
|
||
public static void registerWithDependency() { | ||
/* Comment if computercraft.implementation is not in the source set */ | ||
computerFactory = ComputerBehaviour::new; | ||
ComputerCraftProxy.computerFactory = ComputerBehaviour::new; | ||
} | ||
public static AbstractComputerBehaviour behaviour(SmartBlockEntity sbe) { | ||
if (computerFactory == null) | ||
return fallbackFactory.apply(sbe); | ||
return computerFactory.apply(sbe); | ||
if (ComputerCraftProxy.computerFactory == null) | ||
return ComputerCraftProxy.fallbackFactory.apply(sbe); | ||
return ComputerCraftProxy.computerFactory.apply(sbe); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...n/java/dev/ithundxr/createnumismatics/forge/mixin/self/ComputerBehaviourCapabilities.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Numismatics | ||
* Copyright (c) 2024 The Railways Team | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.ithundxr.createnumismatics.forge.mixin.self; | ||
|
||
import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; | ||
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity; | ||
import com.tterrag.registrate.util.nullness.NonNullSupplier; | ||
import dan200.computercraft.api.peripheral.IPeripheral; | ||
import dev.ithundxr.createnumismatics.compat.computercraft.implementation.ComputerBehaviour; | ||
import net.minecraftforge.common.capabilities.Capability; | ||
import net.minecraftforge.common.capabilities.CapabilityManager; | ||
import net.minecraftforge.common.capabilities.CapabilityToken; | ||
import net.minecraftforge.common.util.LazyOptional; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
@Mixin(ComputerBehaviour.class) | ||
public class ComputerBehaviourCapabilities extends AbstractComputerBehaviour { | ||
public ComputerBehaviourCapabilities(SmartBlockEntity te) { | ||
super(te); | ||
} | ||
|
||
private static final Capability<IPeripheral> RAILWAYS$PERIPHERAL_CAPABILITY = CapabilityManager.get(new CapabilityToken<>() {}); | ||
LazyOptional<IPeripheral> railways$peripheral; | ||
@Shadow NonNullSupplier<IPeripheral> peripheralSupplier; | ||
|
||
@Override | ||
public <T> boolean isPeripheralCap(Capability<T> cap) { | ||
return cap == RAILWAYS$PERIPHERAL_CAPABILITY; | ||
} | ||
|
||
@Override | ||
public <T> LazyOptional<T> getPeripheralCapability() { | ||
if (railways$peripheral == null || !railways$peripheral.isPresent()) | ||
railways$peripheral = LazyOptional.of(() -> peripheralSupplier.get()); | ||
return railways$peripheral.cast(); | ||
} | ||
|
||
@Override | ||
public void removePeripheral() { | ||
if (railways$peripheral != null) | ||
railways$peripheral.invalidate(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters