Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public enum SingleOperation implements IPeripheralOperation<SingleOperationContext> {
DIG(1000, 1),
USE_ON_BLOCK(5000, 1),
UPDATE_BLOCK(500, 1),
SUCK(1000, 1),
USE_ON_ANIMAL(2500, 10),
CAPTURE_ANIMAL(50_000, 100),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.srendi.advancedperipherals.common.addons.computercraft.owner;

import dan200.computercraft.api.peripheral.IPeripheral;
import de.srendi.advancedperipherals.common.blocks.base.BaseBlock;
import de.srendi.advancedperipherals.common.blocks.blockentities.InventoryManagerEntity;
import de.srendi.advancedperipherals.common.util.DataStorageUtil;
Expand All @@ -20,7 +21,6 @@
import org.jetbrains.annotations.Nullable;

import java.util.Objects;
import java.util.function.Function;

public class BlockEntityPeripheralOwner<T extends BlockEntity & IPeripheralTileEntity> extends BasePeripheralOwner {

Expand Down Expand Up @@ -90,7 +90,7 @@ public void markDataStorageDirty() {
}

@Override
public <T1> T1 withPlayer(Function<APFakePlayer, T1> function) {
public <T1> T1 withPlayer(APFakePlayer.Action<T1> function) {
throw new NotImplementedException();
}

Expand Down Expand Up @@ -124,4 +124,9 @@ public BlockEntityPeripheralOwner<T> attachFuel() {
attachAbility(PeripheralOwnerAbility.FUEL, new TileEntityFuelAbility<>(this));
return this;
}

@Override
public <U extends IPeripheral> U getConnectedPeripheral(Class<U> type) {
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.srendi.advancedperipherals.common.addons.computercraft.owner;

import dan200.computercraft.api.peripheral.IPeripheral;
import de.srendi.advancedperipherals.common.util.fakeplayer.APFakePlayer;
import de.srendi.advancedperipherals.lib.peripherals.IPeripheralOperation;
import net.minecraft.core.BlockPos;
Expand All @@ -14,7 +15,6 @@
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.function.Function;

public interface IPeripheralOwner {

Expand All @@ -39,7 +39,7 @@ default Vec3 getCenterPos() {

void markDataStorageDirty();

<T> T withPlayer(Function<APFakePlayer, T> function);
<T> T withPlayer(APFakePlayer.Action<T> function);

ItemStack getToolInMainHand();

Expand Down Expand Up @@ -70,4 +70,10 @@ default void attachOperation(Collection<IPeripheralOperation<?>> operations) {
for (IPeripheralOperation<?> operation : operations)
operationAbility.registerOperation(operation);
}

<T extends IPeripheral> T getConnectedPeripheral(Class<T> type);

default boolean hasConnectedPeripheral(Class<? extends IPeripheral> type) {
return getConnectedPeripheral(type) != null;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package de.srendi.advancedperipherals.common.addons.computercraft.owner;

import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.pocket.IPocketAccess;
import de.srendi.advancedperipherals.common.configuration.APConfig;
import de.srendi.advancedperipherals.common.util.DataStorageUtil;
import de.srendi.advancedperipherals.common.util.fakeplayer.APFakePlayer;
import de.srendi.advancedperipherals.lib.peripherals.IBasePeripheral;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.FrontAndTop;
Expand All @@ -17,8 +19,6 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.function.Function;

public class PocketPeripheralOwner extends BasePeripheralOwner {
private final IPocketAccess pocket;

Expand Down Expand Up @@ -97,7 +97,7 @@ public void markDataStorageDirty() {
}

@Override
public <T> T withPlayer(Function<APFakePlayer, T> function) {
public <T> T withPlayer(APFakePlayer.Action<T> function) {
throw new NotImplementedException();
}

Expand Down Expand Up @@ -125,4 +125,18 @@ public boolean isMovementPossible(@NotNull Level level, @NotNull BlockPos pos) {
public boolean move(@NotNull Level level, @NotNull BlockPos pos) {
return false;
}

@Override
public <T extends IPeripheral> T getConnectedPeripheral(Class<T> type) {
IPeripheral foundPeripheral = pocket.getUpgrades().values().stream()
.filter(peripheral -> {
if (peripheral == null || type.isInstance(peripheral)) {
return false;
}
return peripheral instanceof IBasePeripheral basePeripheral ? basePeripheral.isEnabled() : true;
})
.findFirst()
.orElse(null);
return (T) foundPeripheral;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import com.mojang.authlib.GameProfile;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.shared.TurtlePermissions;
import dan200.computercraft.shared.util.InventoryUtil;
import de.srendi.advancedperipherals.common.util.DataStorageUtil;
import de.srendi.advancedperipherals.common.util.fakeplayer.APFakePlayer;
import de.srendi.advancedperipherals.common.util.fakeplayer.FakePlayerProviderTurtle;
import de.srendi.advancedperipherals.lib.peripherals.IBasePeripheral;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.FrontAndTop;
Expand All @@ -20,7 +22,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.function.Function;
import java.util.stream.Stream;

public class TurtlePeripheralOwner extends BasePeripheralOwner {
public final ITurtleAccess turtle;
Expand Down Expand Up @@ -82,7 +84,7 @@ public void markDataStorageDirty() {
}

@Override
public <T> T withPlayer(Function<APFakePlayer, T> function) {
public <T> T withPlayer(APFakePlayer.Action<T> function) {
return FakePlayerProviderTurtle.withPlayer(turtle, function);
}

Expand Down Expand Up @@ -132,4 +134,19 @@ public TurtlePeripheralOwner attachFuel(int maxFuelConsumptionLevel) {
attachAbility(PeripheralOwnerAbility.FUEL, new TurtleFuelAbility(this, maxFuelConsumptionLevel));
return this;
}

@Override
public <T extends IPeripheral> T getConnectedPeripheral(Class<T> type) {
IPeripheral foundPeripheral = Stream.of(TurtleSide.values())
.map(side -> turtle.getPeripheral(side))
.filter(peripheral -> {
if (peripheral == null || type.isInstance(peripheral)) {
return false;
}
return peripheral instanceof IBasePeripheral basePeripheral ? basePeripheral.isEnabled() : true;
})
.findFirst()
.orElse(null);
return (T) foundPeripheral;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@

import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.TurtleSide;
import de.srendi.advancedperipherals.AdvancedPeripherals;
import de.srendi.advancedperipherals.common.addons.computercraft.operations.AutomataCoreTier;
import de.srendi.advancedperipherals.common.configuration.APConfig;

public class OverpoweredEndAutomataCorePeripheral extends EndAutomataCorePeripheral {

public static final String TYPE = "overpowered_end_automata";

public OverpoweredEndAutomataCorePeripheral(ITurtleAccess turtle, TurtleSide side) {
super(TYPE, turtle, side, AutomataCoreTier.OVERPOWERED_TIER2);
setAttribute(ATTR_STORING_TOOL_DURABILITY);
}

public void addRotationCycle(int count) {
super.addRotationCycle(count);
if (AdvancedPeripherals.RANDOM.nextDouble() <= APConfig.METAPHYSICS_CONFIG.overpoweredAutomataBreakChance.get())
owner.destroyUpgrade();
@Override
public boolean canActiveOverpower() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@

import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.TurtleSide;
import de.srendi.advancedperipherals.AdvancedPeripherals;
import de.srendi.advancedperipherals.common.addons.computercraft.operations.AutomataCoreTier;
import de.srendi.advancedperipherals.common.configuration.APConfig;

public class OverpoweredHusbandryAutomataCorePeripheral extends HusbandryAutomataCorePeripheral {

public static final String TYPE = "overpowered_husbandry_automata";

public OverpoweredHusbandryAutomataCorePeripheral(ITurtleAccess turtle, TurtleSide side) {
super(TYPE, turtle, side, AutomataCoreTier.OVERPOWERED_TIER2);
setAttribute(ATTR_STORING_TOOL_DURABILITY);
}

@Override
public void addRotationCycle(int count) {
super.addRotationCycle(count);
if (AdvancedPeripherals.RANDOM.nextDouble() <= APConfig.METAPHYSICS_CONFIG.overpoweredAutomataBreakChance.get())
owner.destroyUpgrade();
public boolean canActiveOverpower() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@

import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.TurtleSide;
import de.srendi.advancedperipherals.AdvancedPeripherals;
import de.srendi.advancedperipherals.common.addons.computercraft.operations.AutomataCoreTier;
import de.srendi.advancedperipherals.common.configuration.APConfig;

public class OverpoweredWeakAutomataCorePeripheral extends WeakAutomataCorePeripheral {

public static final String TYPE = "overpowered_weak_automata";

public OverpoweredWeakAutomataCorePeripheral(ITurtleAccess turtle, TurtleSide side) {
super(TYPE, turtle, side, AutomataCoreTier.OVERPOWERED_TIER1);
setAttribute(ATTR_STORING_TOOL_DURABILITY);
}

@Override
public void addRotationCycle(int count) {
super.addRotationCycle(count);
if (AdvancedPeripherals.RANDOM.nextDouble() <= APConfig.METAPHYSICS_CONFIG.overpoweredAutomataBreakChance.get())
owner.destroyUpgrade();
public boolean canActiveOverpower() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ public static void addIntegrationPlugin(Function<AutomataCorePeripheral, IPeriph
public boolean isEnabled() {
return APConfig.METAPHYSICS_CONFIG.enableWeakAutomataCore.get();
}

@Override
public double getBreakChance() {
return APConfig.METAPHYSICS_CONFIG.overpoweredAutomataBreakChance.get();
}
}
Loading