1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-10-30 05:12:58 +00:00

Initial pass of the API breaking changes for 1.19.3 (#1232)

- Remove deprecated API members in prep for 1.19.3. This allows us to
   remove the mc-stubs and forge-stubs projects.

 - Make several methods take a MinecraftServer instead of a Level (or
   nothing at all).

 - Remove I prefixes from a whole bunch of interfaces, making things a
   little more consistent with Java conventions.

   This avoids touching the "main" interfaces people consume for now. I
   want to do that another Minecraft version, to avoid making the update
   too painful.

 - Remove IFileSystem and associated getters. This has never worked very
   well and I don't think has got much (any?) usage.
This commit is contained in:
Jonathan Coates
2022-12-03 15:02:00 +00:00
committed by GitHub
parent 95c57e843d
commit 87c6d3aef6
157 changed files with 619 additions and 1272 deletions

View File

@@ -6,7 +6,7 @@
package dan200.computercraft.api;
import dan200.computercraft.api.lua.GenericSource;
import dan200.computercraft.api.network.wired.IWiredElement;
import dan200.computercraft.api.network.wired.WiredElement;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.peripheral.IPeripheralProvider;
import dan200.computercraft.impl.ComputerCraftAPIForgeService;
@@ -20,8 +20,6 @@ import net.minecraftforge.common.util.LazyOptional;
* The forge-specific entrypoint for ComputerCraft's API.
*/
public final class ForgeComputerCraftAPI {
// TODO(1.19.3): Rename me to ComputerCraftAPIForge
private ForgeComputerCraftAPI() {
}
@@ -53,9 +51,9 @@ public final class ForgeComputerCraftAPI {
* @param pos The position the block exists in
* @param side The side to extract the network element from
* @return The element's node
* @see IWiredElement#getNode()
* @see WiredElement#getNode()
*/
public static LazyOptional<IWiredElement> getWiredElementAt(BlockGetter world, BlockPos pos, Direction side) {
public static LazyOptional<WiredElement> getWiredElementAt(BlockGetter world, BlockPos pos, Direction side) {
return getInstance().getWiredElementAt(world, pos, side);
}

View File

@@ -0,0 +1,37 @@
/*
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.peripheral;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.common.util.LazyOptional;
/**
* This interface is used to create peripheral implementations for blocks.
* <p>
* If you have a {@link BlockEntity} which acts as a peripheral, you may alternatively expose the {@link IPeripheral}
* capability.
* <p>
* {@code dan200.computercraft.api.ForgeComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)} should be used
* to register a peripheral provider.
*/
@FunctionalInterface
public interface IPeripheralProvider {
// TODO(1.19.3): Move to Forge and fix link above.
/**
* Produce an peripheral implementation from a block location.
*
* @param world The world the block is in.
* @param pos The position the block is at.
* @param side The side to get the peripheral from.
* @return A peripheral, or {@link LazyOptional#empty()} if there is not a peripheral here you'd like to handle.
*/
LazyOptional<IPeripheral> getPeripheral(Level world, BlockPos pos, Direction side);
}

View File

@@ -1,38 +0,0 @@
/*
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.turtle.event;
import dan200.computercraft.api.turtle.ITurtleAccess;
import net.minecraftforge.eventbus.api.Event;
import java.util.Objects;
/**
* A base class for all events concerning a turtle. This will only ever constructed and fired on the server side,
* so sever specific methods on {@link ITurtleAccess} are safe to use.
* <p>
* You should generally not need to subscribe to this event, preferring one of the more specific classes.
*
* @deprecated No longer needed, see {@link TurtleRefuelEvent}.
*/
@Deprecated(forRemoval = true)
public abstract class TurtleEvent extends Event {
private final ITurtleAccess turtle;
protected TurtleEvent(ITurtleAccess turtle) {
Objects.requireNonNull(turtle, "turtle cannot be null");
this.turtle = turtle;
}
/**
* Get the turtle which is performing this action.
*
* @return The access for this turtle.
*/
public ITurtleAccess getTurtle() {
return turtle;
}
}

View File

@@ -1,86 +0,0 @@
/*
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.turtle.event;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.TurtleRefuelHandler;
import net.minecraft.world.item.ItemStack;
import javax.annotation.Nullable;
import java.util.Objects;
/**
* Fired when a turtle attempts to refuel from an item.
* <p>
* One may use {@link #setHandler(Handler)} to register a custom fuel provider for a given item.
*
* @deprecated Use {@link TurtleRefuelHandler} instead.
*/
@Deprecated(forRemoval = true)
public class TurtleRefuelEvent extends TurtleEvent {
private final ItemStack stack;
private @Nullable Handler handler;
public TurtleRefuelEvent(ITurtleAccess turtle, ItemStack stack) {
super(turtle);
Objects.requireNonNull(turtle, "turtle cannot be null");
this.stack = stack;
}
/**
* Get the stack we are attempting to refuel from.
* <p>
* Do not modify the returned stack - all modifications should be done within the {@link Handler}.
*
* @return The stack to refuel from.
*/
public ItemStack getStack() {
return stack;
}
/**
* Get the refuel handler for this stack.
*
* @return The refuel handler, or {@code null} if none has currently been set.
* @see #setHandler(Handler)
*/
@Nullable
public Handler getHandler() {
return handler;
}
/**
* Set the refuel handler for this stack.
* <p>
* You should call this if you can actually refuel from this item, and ideally only if there are no existing
* handlers.
*
* @param handler The new refuel handler.
* @see #getHandler()
*/
public void setHandler(@Nullable Handler handler) {
this.handler = handler;
}
/**
* Handles refuelling a turtle from a specific item.
*/
@FunctionalInterface
public interface Handler {
/**
* Refuel a turtle using an item.
*
* @param turtle The turtle to refuel.
* @param stack The stack to refuel with.
* @param slot The slot the stack resides within. This may be used to modify the inventory afterwards.
* @param limit The maximum number of refuel operations to perform. This will often correspond to the number of
* items to consume.
* @return The amount of fuel gained.
*/
int refuel(ITurtleAccess turtle, ItemStack stack, int slot, int limit);
}
}

View File

@@ -7,8 +7,13 @@ package dan200.computercraft.impl;
import dan200.computercraft.api.ForgeComputerCraftAPI;
import dan200.computercraft.api.detail.DetailRegistry;
import dan200.computercraft.api.network.wired.WiredElement;
import dan200.computercraft.api.peripheral.IPeripheralProvider;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.BlockGetter;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fluids.FluidStack;
import org.jetbrains.annotations.ApiStatus;
@@ -25,11 +30,11 @@ public interface ComputerCraftAPIForgeService extends ComputerCraftAPIService {
return (ComputerCraftAPIForgeService) ComputerCraftAPIService.get();
}
@Override
void registerPeripheralProvider(IPeripheralProvider provider);
@Override
void registerGenericCapability(Capability<?> capability);
LazyOptional<WiredElement> getWiredElementAt(BlockGetter world, BlockPos pos, Direction side);
DetailRegistry<FluidStack> getFluidStackDetailRegistry();
}