mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-08-30 09:07:55 +00:00
Some basic fixes, will work on this some other time.
This commit is contained in:
@@ -24,21 +24,21 @@ import dan200.computercraft.shared.*;
|
||||
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork;
|
||||
import dan200.computercraft.shared.util.IDAssigner;
|
||||
import dan200.computercraft.shared.wired.WiredNode;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.resource.ReloadableResourceManager;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.swing.text.html.Option;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Optional;
|
||||
|
||||
import static dan200.computercraft.shared.Capabilities.CAPABILITY_WIRED_ELEMENT;
|
||||
|
||||
@@ -54,24 +54,24 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
||||
|
||||
public static InputStream getResourceFile( String domain, String subPath )
|
||||
{
|
||||
ReloadableResourceManager manager = (ReloadableResourceManager) ServerLifecycleHooks.getCurrentServer().getDataPackRegistries().getResourceManager();
|
||||
try
|
||||
{
|
||||
if (FabricLoader.getInstance().getGameInstance() instanceof MinecraftServer) {
|
||||
ReloadableResourceManager manager = (ReloadableResourceManager) ((MinecraftServer) FabricLoader.getInstance().getGameInstance()).getDataPackManager();
|
||||
try {
|
||||
return manager.getResource(new Identifier(domain, subPath)).getInputStream();
|
||||
}
|
||||
catch( IOException ignored )
|
||||
{
|
||||
} catch (IOException ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getInstalledVersion()
|
||||
{
|
||||
if( version != null ) return version;
|
||||
return version = ModList.get().getModContainerById( ComputerCraft.MOD_ID )
|
||||
.map( x -> x.getModInfo().getVersion().toString() )
|
||||
return version = FabricLoader.getInstance().getModContainer( ComputerCraft.MOD_ID )
|
||||
.map( x -> x.getMetadata().getVersion().toString() )
|
||||
.orElse( "unknown" );
|
||||
}
|
||||
|
||||
@@ -97,10 +97,13 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
||||
@Override
|
||||
public IMount createResourceMount( @Nonnull String domain, @Nonnull String subPath )
|
||||
{
|
||||
ReloadableResourceManager manager = (ReloadableResourceManager) ServerLifecycleHooks.getCurrentServer().getDataPackRegistries().getResourceManager();
|
||||
if (FabricLoader.getInstance().getGameInstance() instanceof MinecraftServer) {
|
||||
ReloadableResourceManager manager = (ReloadableResourceManager) ((MinecraftServer) FabricLoader.getInstance().getGameInstance()).getDataPackManager();
|
||||
ResourceMount mount = ResourceMount.get(domain, subPath, manager);
|
||||
return mount.exists("") ? mount : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPeripheralProvider( @Nonnull IPeripheralProvider provider )
|
||||
@@ -160,9 +163,11 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public LazyOptional<IWiredElement> getWiredElementAt( @Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
public Optional<IWiredElement> getWiredElementAt( @Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
{
|
||||
BlockEntity tile = world.getBlockEntity( pos );
|
||||
return tile == null ? LazyOptional.empty() : tile.getCapability( CAPABILITY_WIRED_ELEMENT, side );
|
||||
// TODO Fix this thing
|
||||
// BlockEntity tile = world.getBlockEntity( pos );
|
||||
// return tile == null ? Optional.empty() : tile.getCapability( CAPABILITY_WIRED_ELEMENT, side );
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
@@ -23,10 +23,10 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* The static entry point to the ComputerCraft API.
|
||||
@@ -218,7 +218,7 @@ public final class ComputerCraftAPI
|
||||
* @see IWiredElement#getNode()
|
||||
*/
|
||||
@Nonnull
|
||||
public static LazyOptional<IWiredElement> getWiredElementAt( @Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
public static Optional<IWiredElement> getWiredElementAt(@Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
{
|
||||
return getInstance().getWiredElementAt( world, pos, side );
|
||||
}
|
||||
@@ -275,6 +275,6 @@ public final class ComputerCraftAPI
|
||||
IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element );
|
||||
|
||||
@Nonnull
|
||||
LazyOptional<IWiredElement> getWiredElementAt( @Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||
Optional<IWiredElement> getWiredElementAt( @Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@
|
||||
package dan200.computercraft.api.peripheral;
|
||||
|
||||
import dan200.computercraft.api.lua.LuaFunction;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -14,8 +13,8 @@ import javax.annotation.Nullable;
|
||||
/**
|
||||
* The interface that defines a peripheral.
|
||||
*
|
||||
* In order to expose a peripheral for your block or tile entity, you may either attach a {@link Capability}, or
|
||||
* register a {@link IPeripheralProvider}. This <em>cannot</em> be implemented {@link IPeripheral} directly on the tile.
|
||||
* In order to expose a peripheral for your block or tile entity, you register a {@link IPeripheralProvider}.
|
||||
* This <em>cannot</em> be implemented {@link IPeripheral} directly on the tile.
|
||||
*
|
||||
* Peripherals should provide a series of methods to the user, either using {@link LuaFunction} or by implementing
|
||||
* {@link IDynamicPeripheral}.
|
||||
|
@@ -5,17 +5,18 @@
|
||||
*/
|
||||
package dan200.computercraft.api.peripheral;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* This interface is used to create peripheral implementations for blocks.
|
||||
*
|
||||
* If you have a {@link TileEntity} which acts as a peripheral, you may alternatively expose the {@link IPeripheral}
|
||||
* If you have a {@link BlockEntity} which acts as a peripheral, you may alternatively expose the {@link IPeripheral}
|
||||
* capability.
|
||||
*
|
||||
* @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)
|
||||
@@ -29,9 +30,9 @@ public interface IPeripheralProvider
|
||||
* @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.
|
||||
* @return A peripheral, or {@link Optional#empty()} if there is not a peripheral here you'd like to handle.
|
||||
* @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)
|
||||
*/
|
||||
@Nonnull
|
||||
LazyOptional<IPeripheral> getPeripheral( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||
Optional<IPeripheral> getPeripheral( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||
}
|
||||
|
@@ -10,7 +10,6 @@ import net.minecraft.item.ItemConvertible;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraftforge.common.util.NonNullSupplier;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.function.Supplier;
|
||||
@@ -24,49 +23,27 @@ public abstract class AbstractPocketUpgrade implements IPocketUpgrade
|
||||
{
|
||||
private final Identifier id;
|
||||
private final String adjective;
|
||||
private final NonNullSupplier<ItemStack> stack;
|
||||
private final ItemStack stack;
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, String adjective, NonNullSupplier<ItemStack> stack )
|
||||
protected AbstractPocketUpgrade( Identifier id, String adjective, ItemConvertible item )
|
||||
{
|
||||
this.id = id;
|
||||
this.adjective = adjective;
|
||||
this.stack = stack;
|
||||
this.stack = new ItemStack(item);
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, NonNullSupplier<ItemStack> item )
|
||||
protected AbstractPocketUpgrade( Identifier id, ItemConvertible item )
|
||||
{
|
||||
this( id, Util.createTranslationKey( "upgrade", id ) + ".adjective", item );
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, String adjective, ItemStack stack )
|
||||
{
|
||||
this( id, adjective, () -> stack );
|
||||
this.id = id;
|
||||
this.adjective = adjective;
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, ItemStack stack )
|
||||
{
|
||||
this( id, () -> stack );
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, String adjective, ItemConvertible item )
|
||||
{
|
||||
this( id, adjective, new CachedStack( () -> item ) );
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, ItemConvertible item )
|
||||
{
|
||||
this( id, new CachedStack( () -> item ) );
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, String adjective, Supplier<? extends ItemConvertible> item )
|
||||
{
|
||||
this( id, adjective, new CachedStack( item ) );
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, Supplier<? extends ItemConvertible> item )
|
||||
{
|
||||
this( id, new CachedStack( item ) );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@@ -86,32 +63,6 @@ public abstract class AbstractPocketUpgrade implements IPocketUpgrade
|
||||
@Override
|
||||
public final ItemStack getCraftingItem()
|
||||
{
|
||||
return stack.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Caches the construction of an item stack.
|
||||
*
|
||||
* @see dan200.computercraft.api.turtle.AbstractTurtleUpgrade For explanation of this class.
|
||||
*/
|
||||
private static final class CachedStack implements NonNullSupplier<ItemStack>
|
||||
{
|
||||
private final Supplier<? extends ItemConvertible> provider;
|
||||
private Item item;
|
||||
private ItemStack stack;
|
||||
|
||||
CachedStack( Supplier<? extends ItemConvertible> provider )
|
||||
{
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack get()
|
||||
{
|
||||
Item item = provider.get().asItem();
|
||||
if( item == this.item && stack != null ) return stack;
|
||||
return stack = new ItemStack( this.item = item );
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
@@ -10,7 +10,6 @@ import net.minecraft.item.ItemConvertible;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraftforge.common.util.NonNullSupplier;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.function.Supplier;
|
||||
@@ -25,50 +24,27 @@ public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade
|
||||
private final Identifier id;
|
||||
private final TurtleUpgradeType type;
|
||||
private final String adjective;
|
||||
private final NonNullSupplier<ItemStack> stack;
|
||||
private final ItemStack stack;
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, String adjective, NonNullSupplier<ItemStack> stack )
|
||||
{
|
||||
protected AbstractTurtleUpgrade(Identifier id, TurtleUpgradeType type, String adjective, ItemConvertible item) {
|
||||
this(id, type, adjective, new ItemStack(item));
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade(Identifier id, TurtleUpgradeType type, String adjective, ItemStack stack) {
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
this.adjective = adjective;
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, NonNullSupplier<ItemStack> stack )
|
||||
{
|
||||
protected AbstractTurtleUpgrade(Identifier id, TurtleUpgradeType type, ItemConvertible item) {
|
||||
this(id, type, new ItemStack(item));
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade(Identifier id, TurtleUpgradeType type, ItemStack stack) {
|
||||
this(id, type, Util.createTranslationKey("upgrade", id) + ".adjective", stack);
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, String adjective, ItemStack stack )
|
||||
{
|
||||
this( id, type, adjective, () -> stack );
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, ItemStack stack )
|
||||
{
|
||||
this( id, type, () -> stack );
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, String adjective, ItemConvertible item )
|
||||
{
|
||||
this( id, type, adjective, new CachedStack( () -> item ) );
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, ItemConvertible item )
|
||||
{
|
||||
this( id, type, new CachedStack( () -> item ) );
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, String adjective, Supplier<? extends ItemConvertible> item )
|
||||
{
|
||||
this( id, type, adjective, new CachedStack( item ) );
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, Supplier<? extends ItemConvertible> item )
|
||||
{
|
||||
this( id, type, new CachedStack( item ) );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@@ -95,32 +71,6 @@ public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade
|
||||
@Override
|
||||
public final ItemStack getCraftingItem()
|
||||
{
|
||||
return stack.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* A supplier which converts an item into an item stack.
|
||||
*
|
||||
* Constructing item stacks is somewhat expensive due to attaching capabilities. We cache it if given a consistent item.
|
||||
*/
|
||||
private static final class CachedStack implements NonNullSupplier<ItemStack>
|
||||
{
|
||||
private final Supplier<? extends ItemConvertible> provider;
|
||||
private Item item;
|
||||
private ItemStack stack;
|
||||
|
||||
CachedStack( Supplier<? extends ItemConvertible> provider )
|
||||
{
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack get()
|
||||
{
|
||||
Item item = provider.get().asItem();
|
||||
if( item == this.item && stack != null ) return stack;
|
||||
return stack = new ItemStack( this.item = item );
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
267
src/main/java/dan200/computercraft/api/turtle/FakePlayer.java
Normal file
267
src/main/java/dan200/computercraft/api/turtle/FakePlayer.java
Normal file
@@ -0,0 +1,267 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.turtle;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.crypto.SecretKey;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
|
||||
import net.minecraft.block.entity.CommandBlockBlockEntity;
|
||||
import net.minecraft.block.entity.SignBlockEntity;
|
||||
import net.minecraft.command.argument.EntityAnchorArgumentType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||
import net.minecraft.entity.passive.HorseBaseEntity;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.ClientConnection;
|
||||
import net.minecraft.network.MessageType;
|
||||
import net.minecraft.network.NetworkSide;
|
||||
import net.minecraft.network.NetworkState;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.packet.c2s.play.RequestCommandCompletionsC2SPacket;
|
||||
import net.minecraft.network.packet.c2s.play.VehicleMoveC2SPacket;
|
||||
import net.minecraft.recipe.Recipe;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.network.ServerPlayerInteractionManager;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.village.TraderOfferList;
|
||||
import net.minecraft.world.GameMode;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
|
||||
/**
|
||||
* A wrapper for {@link ServerPlayerEntity} which denotes a "fake" player.
|
||||
*
|
||||
* Please note that this does not implement any of the traditional fake player behaviour. It simply exists to prevent me passing in normal players.
|
||||
*/
|
||||
public class FakePlayer extends ServerPlayerEntity {
|
||||
public FakePlayer(ServerWorld world, GameProfile gameProfile) {
|
||||
super(world.getServer(), world, gameProfile, new ServerPlayerInteractionManager(world));
|
||||
this.networkHandler = new FakeNetHandler(this);
|
||||
}
|
||||
|
||||
// region Direct networkHandler access
|
||||
@Override
|
||||
public void enterCombat() { }
|
||||
|
||||
@Override
|
||||
public void endCombat() { }
|
||||
|
||||
@Override
|
||||
public void tick() { }
|
||||
|
||||
@Override
|
||||
public void playerTick() { }
|
||||
|
||||
@Override
|
||||
public void onDeath(DamageSource damage) { }
|
||||
|
||||
@Override
|
||||
public boolean startRiding(Entity entity, boolean flag) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopRiding() { }
|
||||
|
||||
@Override
|
||||
public void openEditSignScreen(SignBlockEntity tile) { }
|
||||
|
||||
@Override
|
||||
public OptionalInt openHandledScreen(@Nullable NamedScreenHandlerFactory container) {
|
||||
return OptionalInt.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTradeOffers(int id, TraderOfferList list, int level, int experience, boolean levelled, boolean refreshable) { }
|
||||
|
||||
@Override
|
||||
public void openHorseInventory(HorseBaseEntity horse, Inventory inventory) { }
|
||||
|
||||
@Override
|
||||
public void openEditBookScreen(ItemStack stack, Hand hand) { }
|
||||
|
||||
@Override
|
||||
public void openCommandBlockScreen(CommandBlockBlockEntity block) { }
|
||||
|
||||
@Override
|
||||
public void onSlotUpdate(ScreenHandler container, int slot, ItemStack stack) { }
|
||||
|
||||
@Override
|
||||
public void onHandlerRegistered(ScreenHandler container, DefaultedList<ItemStack> defaultedList) { }
|
||||
|
||||
@Override
|
||||
public void onPropertyUpdate(ScreenHandler container, int key, int value) { }
|
||||
|
||||
@Override
|
||||
public void closeHandledScreen() { }
|
||||
|
||||
@Override
|
||||
public void updateCursorStack() { }
|
||||
|
||||
@Override
|
||||
public int unlockRecipes(Collection<Recipe<?>> recipes) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Indirect
|
||||
@Override
|
||||
public int lockRecipes(Collection<Recipe<?>> recipes) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(Text textComponent, boolean status) { }
|
||||
|
||||
@Override
|
||||
protected void consumeItem() { }
|
||||
|
||||
@Override
|
||||
public void lookAt(EntityAnchorArgumentType.EntityAnchor anchor, Vec3d vec3d) {}
|
||||
|
||||
@Override
|
||||
public void method_14222(EntityAnchorArgumentType.EntityAnchor self, Entity entity, EntityAnchorArgumentType.EntityAnchor target) { }
|
||||
|
||||
@Override
|
||||
protected void onStatusEffectApplied(StatusEffectInstance statusEffectInstance) { }
|
||||
|
||||
@Override
|
||||
protected void onStatusEffectUpgraded(StatusEffectInstance statusEffectInstance, boolean particles) { }
|
||||
|
||||
@Override
|
||||
protected void onStatusEffectRemoved(StatusEffectInstance statusEffectInstance) { }
|
||||
|
||||
@Override
|
||||
public void requestTeleport(double x, double y, double z) { }
|
||||
|
||||
@Override
|
||||
public void setGameMode(GameMode gameMode) { }
|
||||
|
||||
@Override
|
||||
public String getIp() {
|
||||
return "[Fake Player]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendResourcePackUrl(String url, String hash) { }
|
||||
|
||||
@Override
|
||||
public void onStoppedTracking(Entity entity) { }
|
||||
|
||||
@Override
|
||||
public void setCameraEntity(Entity entity) { }
|
||||
|
||||
@Override
|
||||
public void teleport(ServerWorld serverWorld, double x, double y, double z, float pitch, float yaw) { }
|
||||
|
||||
@Override
|
||||
public void sendInitialChunkPackets(ChunkPos chunkPos, Packet<?> packet, Packet<?> packet2) { }
|
||||
|
||||
@Override
|
||||
public void sendUnloadChunkPacket(ChunkPos chunkPos) { }
|
||||
|
||||
@Override
|
||||
public void playSound(SoundEvent soundEvent, SoundCategory soundCategory, float volume, float pitch) { }
|
||||
|
||||
@Override
|
||||
public Entity moveToWorld(ServerWorld destination) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void wakeUp(boolean bl, boolean updateSleepingPlayers) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(Text message, MessageType type, UUID senderUuid) {
|
||||
|
||||
}
|
||||
|
||||
private static class FakeNetHandler extends ServerPlayNetworkHandler {
|
||||
FakeNetHandler(ServerPlayerEntity player) {
|
||||
super(player.server, new FakeConnection(), player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(Text message) { }
|
||||
|
||||
@Override
|
||||
public void onVehicleMove(VehicleMoveC2SPacket move) { }
|
||||
|
||||
@Override
|
||||
public void onRequestCommandCompletions(RequestCommandCompletionsC2SPacket packet) { }
|
||||
|
||||
@Override
|
||||
public void sendPacket(Packet<?> packet, @Nullable GenericFutureListener<? extends Future<? super Void>> listener) { }
|
||||
}
|
||||
|
||||
private static class FakeConnection extends ClientConnection {
|
||||
FakeConnection() {
|
||||
super(NetworkSide.CLIENTBOUND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext active) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState(NetworkState state) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext context, Throwable err) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext context, Packet<?> packet) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Packet<?> packet, @Nullable GenericFutureListener<? extends Future<? super Void>> listener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(Text message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupEncryption(SecretKey key) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableAutoRead() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCompressionThreshold(int size) {
|
||||
}
|
||||
}
|
||||
}
|
@@ -15,7 +15,6 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -148,24 +147,10 @@ public interface ITurtleAccess
|
||||
* Note: this inventory should only be accessed and modified on the server thread.
|
||||
*
|
||||
* @return This turtle's inventory
|
||||
* @see #getItemHandler()
|
||||
*/
|
||||
@Nonnull
|
||||
Inventory getInventory();
|
||||
|
||||
/**
|
||||
* Get the inventory of this turtle as an {@link IItemHandlerModifiable}.
|
||||
*
|
||||
* Note: this inventory should only be accessed and modified on the server thread.
|
||||
*
|
||||
* @return This turtle's inventory
|
||||
* @see #getInventory()
|
||||
* @see IItemHandlerModifiable
|
||||
* @see net.minecraftforge.items.CapabilityItemHandler#ITEM_HANDLER_CAPABILITY
|
||||
*/
|
||||
@Nonnull
|
||||
IItemHandlerModifiable getItemHandler();
|
||||
|
||||
/**
|
||||
* Determine whether this turtle will require fuel when performing actions.
|
||||
*
|
||||
|
@@ -8,17 +8,11 @@ package dan200.computercraft.api.turtle;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.client.TransformedModel;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.api.turtle.event.TurtleAttackEvent;
|
||||
import dan200.computercraft.api.turtle.event.TurtleBlockEvent;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.event.entity.player.AttackEntityEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -96,9 +90,6 @@ public interface ITurtleUpgrade
|
||||
* Will only be called for Tool turtle. Called when turtle.dig() or turtle.attack() is called
|
||||
* by the turtle, and the tool is required to do some work.
|
||||
*
|
||||
* Conforming implementations should fire {@link BlockEvent.BreakEvent} and {@link TurtleBlockEvent.Dig} for
|
||||
* digging, {@link AttackEntityEvent} and {@link TurtleAttackEvent} for attacking.
|
||||
*
|
||||
* @param turtle Access to the turtle that the tool resides on.
|
||||
* @param side Which side of the turtle (left or right) the tool resides on.
|
||||
* @param verb Which action (dig or attack) the turtle is being called on to perform.
|
||||
@@ -119,10 +110,6 @@ public interface ITurtleUpgrade
|
||||
/**
|
||||
* Called to obtain the model to be used when rendering a turtle peripheral.
|
||||
*
|
||||
* This can be obtained from {@link net.minecraft.client.renderer.ItemModelMesher#getItemModel(ItemStack)},
|
||||
* {@link net.minecraft.client.renderer.model.ModelManager#getModel(ModelResourceLocation)} or any other
|
||||
* source.
|
||||
*
|
||||
* @param turtle Access to the turtle that the upgrade resides on. This will be null when getting item models!
|
||||
* @param side Which side of the turtle (left or right) the upgrade resides on.
|
||||
* @return The model that you wish to be used to render your upgrade.
|
||||
|
@@ -7,7 +7,6 @@ package dan200.computercraft.api.turtle.event;
|
||||
|
||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -16,11 +15,11 @@ import java.util.Objects;
|
||||
/**
|
||||
* An event fired when a turtle is performing a known action.
|
||||
*/
|
||||
@Cancelable
|
||||
public class TurtleActionEvent extends TurtleEvent
|
||||
{
|
||||
private final TurtleAction action;
|
||||
private String failureMessage;
|
||||
private boolean cancelled = false;
|
||||
|
||||
public TurtleActionEvent( @Nonnull ITurtleAccess turtle, @Nonnull TurtleAction action )
|
||||
{
|
||||
@@ -44,7 +43,6 @@ public class TurtleActionEvent extends TurtleEvent
|
||||
* @see TurtleCommandResult#failure()
|
||||
* @deprecated Use {@link #setCanceled(boolean, String)} instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void setCanceled( boolean cancel )
|
||||
{
|
||||
@@ -62,7 +60,7 @@ public class TurtleActionEvent extends TurtleEvent
|
||||
*/
|
||||
public void setCanceled( boolean cancel, @Nullable String failureMessage )
|
||||
{
|
||||
super.setCanceled( cancel );
|
||||
this.cancelled = true;
|
||||
this.failureMessage = cancel ? failureMessage : null;
|
||||
}
|
||||
|
||||
@@ -78,4 +76,8 @@ public class TurtleActionEvent extends TurtleEvent
|
||||
{
|
||||
return failureMessage;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
}
|
||||
|
@@ -5,13 +5,8 @@
|
||||
*/
|
||||
package dan200.computercraft.api.turtle.event;
|
||||
|
||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||
import dan200.computercraft.api.turtle.TurtleSide;
|
||||
import dan200.computercraft.api.turtle.TurtleVerb;
|
||||
import dan200.computercraft.api.turtle.*;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import net.minecraftforge.event.entity.player.AttackEntityEvent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Objects;
|
||||
@@ -19,11 +14,6 @@ import java.util.Objects;
|
||||
/**
|
||||
* Fired when a turtle attempts to attack an entity.
|
||||
*
|
||||
* This must be fired by {@link ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction)},
|
||||
* as the base {@code turtle.attack()} command does not fire it.
|
||||
*
|
||||
* Note that such commands should also fire {@link AttackEntityEvent}, so you do not need to listen to both.
|
||||
*
|
||||
* @see TurtleAction#ATTACK
|
||||
*/
|
||||
public class TurtleAttackEvent extends TurtlePlayerEvent
|
||||
|
@@ -6,16 +6,11 @@
|
||||
package dan200.computercraft.api.turtle.event;
|
||||
|
||||
import dan200.computercraft.api.lua.MethodResult;
|
||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||
import dan200.computercraft.api.turtle.TurtleSide;
|
||||
import dan200.computercraft.api.turtle.TurtleVerb;
|
||||
import dan200.computercraft.api.turtle.*;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Map;
|
||||
@@ -72,11 +67,6 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
|
||||
/**
|
||||
* Fired when a turtle attempts to dig a block.
|
||||
*
|
||||
* This must be fired by {@link ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction)},
|
||||
* as the base {@code turtle.dig()} command does not fire it.
|
||||
*
|
||||
* Note that such commands should also fire {@link BlockEvent.BreakEvent}, so you do not need to listen to both.
|
||||
*
|
||||
* @see TurtleAction#DIG
|
||||
*/
|
||||
public static class Dig extends TurtleBlockEvent
|
||||
|
@@ -5,8 +5,8 @@
|
||||
*/
|
||||
package dan200.computercraft.api.turtle.event;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Objects;
|
||||
@@ -19,24 +19,30 @@ import java.util.Objects;
|
||||
*
|
||||
* @see TurtleActionEvent
|
||||
*/
|
||||
public abstract class TurtleEvent extends Event
|
||||
public abstract class TurtleEvent
|
||||
{
|
||||
public static final EventBus EVENT_BUS = new EventBus();
|
||||
|
||||
private final ITurtleAccess turtle;
|
||||
|
||||
protected TurtleEvent( @Nonnull ITurtleAccess turtle )
|
||||
{
|
||||
protected TurtleEvent(@Nonnull ITurtleAccess turtle) {
|
||||
Objects.requireNonNull(turtle, "turtle cannot be null");
|
||||
this.turtle = turtle;
|
||||
}
|
||||
|
||||
public static boolean post(TurtleActionEvent event) {
|
||||
EVENT_BUS.post(event);
|
||||
return event.isCancelled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the turtle which is performing this action.
|
||||
*
|
||||
* @return The access for this turtle.
|
||||
*/
|
||||
@Nonnull
|
||||
public ITurtleAccess getTurtle()
|
||||
{
|
||||
return turtle;
|
||||
public ITurtleAccess getTurtle() {
|
||||
return this.turtle;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -5,12 +5,12 @@
|
||||
*/
|
||||
package dan200.computercraft.api.turtle.event;
|
||||
|
||||
import dan200.computercraft.api.turtle.FakePlayer;
|
||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -21,9 +21,9 @@ import java.util.Objects;
|
||||
*/
|
||||
public abstract class TurtleInventoryEvent extends TurtleBlockEvent
|
||||
{
|
||||
private final IItemHandler handler;
|
||||
private final Inventory handler;
|
||||
|
||||
protected TurtleInventoryEvent( @Nonnull ITurtleAccess turtle, @Nonnull TurtleAction action, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nullable IItemHandler handler )
|
||||
protected TurtleInventoryEvent(@Nonnull ITurtleAccess turtle, @Nonnull TurtleAction action, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nullable Inventory handler )
|
||||
{
|
||||
super( turtle, action, player, world, pos );
|
||||
this.handler = handler;
|
||||
@@ -35,7 +35,7 @@ public abstract class TurtleInventoryEvent extends TurtleBlockEvent
|
||||
* @return The inventory being interacted with, {@code null} if the item will be dropped to/sucked from the world.
|
||||
*/
|
||||
@Nullable
|
||||
public IItemHandler getItemHandler()
|
||||
public Inventory getItemHandler()
|
||||
{
|
||||
return handler;
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public abstract class TurtleInventoryEvent extends TurtleBlockEvent
|
||||
*/
|
||||
public static class Suck extends TurtleInventoryEvent
|
||||
{
|
||||
public Suck( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nullable IItemHandler handler )
|
||||
public Suck( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nullable Inventory handler )
|
||||
{
|
||||
super( turtle, TurtleAction.SUCK, player, world, pos, handler );
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public abstract class TurtleInventoryEvent extends TurtleBlockEvent
|
||||
{
|
||||
private final ItemStack stack;
|
||||
|
||||
public Drop( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nullable IItemHandler handler, @Nonnull ItemStack stack )
|
||||
public Drop( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nullable Inventory handler, @Nonnull ItemStack stack )
|
||||
{
|
||||
super( turtle, TurtleAction.DROP, player, world, pos, handler );
|
||||
|
||||
|
@@ -5,8 +5,8 @@
|
||||
*/
|
||||
package dan200.computercraft.api.turtle.event;
|
||||
|
||||
import dan200.computercraft.api.turtle.FakePlayer;
|
||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Objects;
|
||||
|
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.client;
|
||||
|
||||
import com.sun.org.apache.xpath.internal.operations.Mod;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.client.render.TurtleModelLoader;
|
||||
import dan200.computercraft.shared.Registry;
|
||||
@@ -13,29 +14,26 @@ import dan200.computercraft.shared.media.items.ItemDisk;
|
||||
import dan200.computercraft.shared.media.items.ItemTreasureDisk;
|
||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||
import dan200.computercraft.shared.util.Colour;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
|
||||
import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.client.render.model.ModelRotation;
|
||||
import net.minecraft.client.render.model.UnbakedModel;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.client.util.ModelIdentifier;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.screen.PlayerScreenHandler;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.ColorHandlerEvent;
|
||||
import net.minecraftforge.client.event.ModelBakeEvent;
|
||||
import net.minecraftforge.client.event.ModelRegistryEvent;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.client.model.SimpleModelTransform;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Registers textures and models for items.
|
||||
*/
|
||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD )
|
||||
public final class ClientRegistry
|
||||
{
|
||||
private static final String[] EXTRA_MODELS = new String[] {
|
||||
@@ -69,42 +67,50 @@ public final class ClientRegistry
|
||||
|
||||
private ClientRegistry() {}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerModels( ModelRegistryEvent event )
|
||||
{
|
||||
ModelLoaderRegistry.registerLoader( new Identifier( ComputerCraft.MOD_ID, "turtle" ), TurtleModelLoader.INSTANCE );
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onTextureStitchEvent( TextureStitchEvent.Pre event )
|
||||
{
|
||||
if( !event.getMap().getId().equals( PlayerScreenHandler.BLOCK_ATLAS_TEXTURE ) ) return;
|
||||
|
||||
for( String extra : EXTRA_TEXTURES )
|
||||
{
|
||||
event.addSprite( new Identifier( ComputerCraft.MOD_ID, extra ) );
|
||||
public static void onTextureStitchEvent(SpriteAtlasTexture atlasTexture, ClientSpriteRegistryCallback.Registry registry) {
|
||||
for (String extra : EXTRA_TEXTURES) {
|
||||
registry.register(new Identifier(ComputerCraft.MOD_ID, extra));
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onModelBakeEvent( ModelBakeEvent event )
|
||||
{
|
||||
// Load all extra models
|
||||
ModelLoader loader = event.getModelLoader();
|
||||
Map<Identifier, BakedModel> registry = event.getModelRegistry();
|
||||
public static void onModelBakeEvent(ResourceManager manager, Consumer<ModelIdentifier> out) {
|
||||
for (String model : EXTRA_MODELS) {
|
||||
out.accept(new ModelIdentifier(new Identifier(ComputerCraft.MOD_ID, model), "inventory"));
|
||||
}
|
||||
}
|
||||
|
||||
for( String modelName : EXTRA_MODELS )
|
||||
public static void onItemColours() {
|
||||
ColorProviderRegistry.ITEM.register((stack, layer) -> {
|
||||
return layer == 1 ? ((ItemDisk) stack.getItem()).getColour(stack) : 0xFFFFFF, Registry.ModItems.DISK);
|
||||
});
|
||||
|
||||
ColorProviderRegistry.ITEM.register((stack, layer) -> {
|
||||
switch (layer) {
|
||||
case 0:
|
||||
default:
|
||||
return 0xFFFFFF;
|
||||
case 1: // Frame colour
|
||||
return IColouredItem.getColourBasic(stack);
|
||||
case 2: // Light colour
|
||||
{
|
||||
Identifier location = new Identifier( ComputerCraft.MOD_ID, "item/" + modelName );
|
||||
UnbakedModel model = loader.getOrLoadModel( location );
|
||||
int light = ItemPocketComputer.getLightState(stack);
|
||||
return light == -1 ? Colour.BLACK.getHex() : light;
|
||||
}
|
||||
}
|
||||
}, Registry.ModItems.POCKET_COMPUTER_NORMAL, Registry.ModItems.POCKET_COMPUTER_ADVANCED);
|
||||
|
||||
// Setup turtle colours
|
||||
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex == 0 ? ((IColouredItem) stack.getItem()).getColour(stack) : 0xFFFFFF,
|
||||
ComputerCraft.Blocks.turtleNormal,
|
||||
ComputerCraft.Blocks.turtleAdvanced);
|
||||
}
|
||||
|
||||
private static BakedModel bake(ModelLoader loader, UnbakedModel model) {
|
||||
model.getTextureDependencies(loader::getOrLoadModel, new HashSet<>());
|
||||
|
||||
BakedModel baked = model.bake( loader, ModelLoader.defaultTextureGetter(), SimpleModelTransform.IDENTITY, location );
|
||||
if( baked != null )
|
||||
{
|
||||
registry.put( new ModelIdentifier( new Identifier( ComputerCraft.MOD_ID, modelName ), "inventory" ), baked );
|
||||
}
|
||||
}
|
||||
SpriteAtlasTexture sprite = MinecraftClient.getInstance()
|
||||
.getSpriteAtlas();
|
||||
return model.bake(loader, spriteIdentifier -> MinecraftClient.getInstance()
|
||||
.getSpriteAtlas(spriteIdentifier.getAtlasId()).apply(spriteIdentifier.getTextureId()), ModelRotation.X0_Y0);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
@@ -69,6 +69,7 @@ import net.minecraft.item.Items;
|
||||
import net.minecraft.recipe.RecipeSerializer;
|
||||
import net.minecraft.screen.ScreenHandlerType;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.MutableRegistry;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
@@ -90,162 +91,180 @@ public final class Registry
|
||||
{
|
||||
}
|
||||
|
||||
public static final class ModBlocks
|
||||
{
|
||||
static final DeferredRegister<Block> BLOCKS = DeferredRegister.create( ForgeRegistries.BLOCKS, ComputerCraft.MOD_ID );
|
||||
public static void registerBlocks(MutableRegistry<Block> registry) {
|
||||
// Computers
|
||||
ComputerCraft.Blocks.computerNormal = new BlockComputer(FabricBlockSettings.of(Material.STONE)
|
||||
.hardness(2.0f)
|
||||
.build(), ComputerFamily.NORMAL, TileComputer.FACTORY_NORMAL);
|
||||
|
||||
private static Block.Properties properties()
|
||||
{
|
||||
return Block.Properties.of( Material.STONE ).strength( 2 );
|
||||
ComputerCraft.Blocks.computerAdvanced = new BlockComputer(FabricBlockSettings.of(Material.STONE)
|
||||
.hardness(2.0f)
|
||||
.build(), ComputerFamily.Advanced, TileComputer.FACTORY_ADVANCED);
|
||||
|
||||
ComputerCraft.Blocks.computerCommand = new BlockComputer(FabricBlockSettings.of(Material.STONE)
|
||||
.strength(-1, 6000000.0F)
|
||||
.build(), ComputerFamily.Command, TileCommandComputer.FACTORY);
|
||||
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "computer_normal"), ComputerCraft.Blocks.computerNormal);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "computer_advanced"), ComputerCraft.Blocks.computerAdvanced);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "computer_command"), ComputerCraft.Blocks.computerCommand);
|
||||
|
||||
// Turtles
|
||||
ComputerCraft.Blocks.turtleNormal = new BlockTurtle(FabricBlockSettings.of(Material.STONE)
|
||||
.hardness(2.5f)
|
||||
.build(), ComputerFamily.Normal, TileTurtle.FACTORY_NORMAL);
|
||||
|
||||
ComputerCraft.Blocks.turtleAdvanced = new BlockTurtle(FabricBlockSettings.of(Material.STONE)
|
||||
.hardness(2.5f)
|
||||
.build(), ComputerFamily.Advanced, TileTurtle.FACTORY_ADVANCED);
|
||||
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "turtle_normal"), ComputerCraft.Blocks.turtleNormal);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "turtle_advanced"), ComputerCraft.Blocks.turtleAdvanced);
|
||||
|
||||
// Peripherals
|
||||
ComputerCraft.Blocks.speaker = new BlockSpeaker(FabricBlockSettings.of(Material.STONE)
|
||||
.hardness(2)
|
||||
.build());
|
||||
|
||||
ComputerCraft.Blocks.diskDrive = new BlockDiskDrive(FabricBlockSettings.of(Material.STONE)
|
||||
.hardness(2)
|
||||
.build());
|
||||
|
||||
ComputerCraft.Blocks.monitorNormal = new BlockMonitor(FabricBlockSettings.of(Material.STONE)
|
||||
.hardness(2)
|
||||
.build(), TileMonitor.FACTORY_NORMAL);
|
||||
|
||||
ComputerCraft.Blocks.monitorAdvanced = new BlockMonitor(FabricBlockSettings.of(Material.STONE)
|
||||
.hardness(2)
|
||||
.build(), TileMonitor.FACTORY_ADVANCED);
|
||||
|
||||
ComputerCraft.Blocks.printer = new BlockPrinter(FabricBlockSettings.of(Material.STONE)
|
||||
.hardness(2)
|
||||
.build());
|
||||
|
||||
ComputerCraft.Blocks.wirelessModemNormal = new BlockWirelessModem(FabricBlockSettings.of(Material.STONE)
|
||||
.hardness(2)
|
||||
.build(), TileWirelessModem.FACTORY_NORMAL);
|
||||
|
||||
ComputerCraft.Blocks.wirelessModemAdvanced = new BlockWirelessModem(FabricBlockSettings.of(Material.STONE)
|
||||
.hardness(2)
|
||||
.build(), TileWirelessModem.FACTORY_ADVANCED);
|
||||
|
||||
ComputerCraft.Blocks.wiredModemFull = new BlockWiredModemFull(FabricBlockSettings.of(Material.STONE)
|
||||
.hardness(1.5f)
|
||||
.build());
|
||||
|
||||
ComputerCraft.Blocks.cable = new BlockCable(FabricBlockSettings.of(Material.STONE)
|
||||
.hardness(1.5f)
|
||||
.build());
|
||||
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "speaker"), ComputerCraft.Blocks.speaker);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "disk_drive"), ComputerCraft.Blocks.diskDrive);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "monitor_normal"), ComputerCraft.Blocks.monitorNormal);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "monitor_advanced"), ComputerCraft.Blocks.monitorAdvanced);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "printer"), ComputerCraft.Blocks.printer);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "wireless_modem_normal"), ComputerCraft.Blocks.wirelessModemNormal);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "wireless_modem_advanced"), ComputerCraft.Blocks.wirelessModemAdvanced);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "wired_modem_full"), ComputerCraft.Blocks.wiredModemFull);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "cable"), ComputerCraft.Blocks.cable);
|
||||
}
|
||||
|
||||
private static Block.Properties turtleProperties()
|
||||
{
|
||||
return Block.Properties.of( Material.STONE ).strength( 2.5f );
|
||||
public static void registerTileEntities(MutableRegistry<BlockEntityType<?>> registry) {
|
||||
// Computers
|
||||
registry.add(TileComputer.FACTORY_NORMAL.getId(), TileComputer.FACTORY_NORMAL);
|
||||
registry.add(TileComputer.FACTORY_ADVANCED.getId(), TileComputer.FACTORY_ADVANCED);
|
||||
registry.add(TileCommandComputer.FACTORY.getId(), TileCommandComputer.FACTORY);
|
||||
|
||||
// Turtles
|
||||
registry.add(TileTurtle.FACTORY_NORMAL.getId(), TileTurtle.FACTORY_NORMAL);
|
||||
registry.add(TileTurtle.FACTORY_ADVANCED.getId(), TileTurtle.FACTORY_ADVANCED);
|
||||
|
||||
// Peripherals
|
||||
registry.add(TileSpeaker.FACTORY.getId(), TileSpeaker.FACTORY);
|
||||
registry.add(TileDiskDrive.FACTORY.getId(), TileDiskDrive.FACTORY);
|
||||
registry.add(TilePrinter.FACTORY.getId(), TilePrinter.FACTORY);
|
||||
|
||||
registry.add(TileMonitor.FACTORY_NORMAL.getId(), TileMonitor.FACTORY_NORMAL);
|
||||
registry.add(TileMonitor.FACTORY_ADVANCED.getId(), TileMonitor.FACTORY_ADVANCED);
|
||||
|
||||
registry.add(TileWirelessModem.FACTORY_NORMAL.getId(), TileWirelessModem.FACTORY_NORMAL);
|
||||
registry.add(TileWirelessModem.FACTORY_ADVANCED.getId(), TileWirelessModem.FACTORY_ADVANCED);
|
||||
registry.add(TileCable.FACTORY.getId(), TileCable.FACTORY);
|
||||
registry.add(TileWiredModemFull.FACTORY.getId(), TileWiredModemFull.FACTORY);
|
||||
}
|
||||
|
||||
private static Block.Properties modemProperties()
|
||||
{
|
||||
return Block.Properties.of( Material.STONE ).strength( 1.5f );
|
||||
}
|
||||
public static void registerItems(MutableRegistry<Item> registry) {
|
||||
// Computer
|
||||
ComputerCraft.Items.computerNormal = new ItemComputer(ComputerCraft.Blocks.computerNormal, defaultItem());
|
||||
ComputerCraft.Items.computerAdvanced = new ItemComputer(ComputerCraft.Blocks.computerAdvanced, defaultItem());
|
||||
ComputerCraft.Items.computerCommand = new ItemComputer(ComputerCraft.Blocks.computerCommand, defaultItem());
|
||||
|
||||
public static final RegistryObject<BlockComputer> COMPUTER_NORMAL = BLOCKS.register( "computer_normal",
|
||||
() -> new BlockComputer( properties(), ComputerFamily.NORMAL, ModTiles.COMPUTER_NORMAL ) );
|
||||
public static final RegistryObject<BlockComputer> COMPUTER_ADVANCED = BLOCKS.register( "computer_advanced",
|
||||
() -> new BlockComputer( properties(), ComputerFamily.ADVANCED, ModTiles.COMPUTER_ADVANCED ) );
|
||||
registerItemBlock(registry, ComputerCraft.Items.computerNormal);
|
||||
registerItemBlock(registry, ComputerCraft.Items.computerAdvanced);
|
||||
registerItemBlock(registry, ComputerCraft.Items.computerCommand);
|
||||
|
||||
public static final RegistryObject<BlockComputer> COMPUTER_COMMAND = BLOCKS.register( "computer_command", () -> new BlockComputer(
|
||||
Block.Properties.of( Material.STONE ).strength( -1, 6000000.0F ),
|
||||
ComputerFamily.COMMAND, ModTiles.COMPUTER_COMMAND
|
||||
) );
|
||||
// Turtle
|
||||
ComputerCraft.Items.turtleNormal = new ItemTurtle(ComputerCraft.Blocks.turtleNormal, defaultItem());
|
||||
ComputerCraft.Items.turtleAdvanced = new ItemTurtle(ComputerCraft.Blocks.turtleAdvanced, defaultItem());
|
||||
|
||||
public static final RegistryObject<BlockTurtle> TURTLE_NORMAL = BLOCKS.register( "turtle_normal",
|
||||
() -> new BlockTurtle( turtleProperties(), ComputerFamily.NORMAL, ModTiles.TURTLE_NORMAL ) );
|
||||
public static final RegistryObject<BlockTurtle> TURTLE_ADVANCED = BLOCKS.register( "turtle_advanced",
|
||||
() -> new BlockTurtle( turtleProperties(), ComputerFamily.ADVANCED, ModTiles.TURTLE_ADVANCED ) );
|
||||
registerItemBlock(registry, ComputerCraft.Items.turtleNormal);
|
||||
registerItemBlock(registry, ComputerCraft.Items.turtleAdvanced);
|
||||
|
||||
public static final RegistryObject<BlockSpeaker> SPEAKER = BLOCKS.register( "speaker", () -> new BlockSpeaker( properties() ) );
|
||||
public static final RegistryObject<BlockDiskDrive> DISK_DRIVE = BLOCKS.register( "disk_drive", () -> new BlockDiskDrive( properties() ) );
|
||||
public static final RegistryObject<BlockPrinter> PRINTER = BLOCKS.register( "printer", () -> new BlockPrinter( properties() ) );
|
||||
// Pocket computer
|
||||
ComputerCraft.Items.pocketComputerNormal = new ItemPocketComputer(defaultItem().maxCount(1), ComputerFamily.Normal);
|
||||
ComputerCraft.Items.pocketComputerAdvanced = new ItemPocketComputer(defaultItem().maxCount(1), ComputerFamily.Advanced);
|
||||
|
||||
public static final RegistryObject<BlockMonitor> MONITOR_NORMAL = BLOCKS.register( "monitor_normal",
|
||||
() -> new BlockMonitor( properties(), ModTiles.MONITOR_NORMAL ) );
|
||||
public static final RegistryObject<BlockMonitor> MONITOR_ADVANCED = BLOCKS.register( "monitor_advanced",
|
||||
() -> new BlockMonitor( properties(), ModTiles.MONITOR_ADVANCED ) );
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "pocket_computer_normal"), ComputerCraft.Items.pocketComputerNormal);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "pocket_computer_advanced"), ComputerCraft.Items.pocketComputerAdvanced);
|
||||
|
||||
public static final RegistryObject<BlockWirelessModem> WIRELESS_MODEM_NORMAL = BLOCKS.register( "wireless_modem_normal",
|
||||
() -> new BlockWirelessModem( properties(), ModTiles.WIRELESS_MODEM_NORMAL ) );
|
||||
public static final RegistryObject<BlockWirelessModem> WIRELESS_MODEM_ADVANCED = BLOCKS.register( "wireless_modem_advanced",
|
||||
() -> new BlockWirelessModem( properties(), ModTiles.WIRELESS_MODEM_ADVANCED ) );
|
||||
// Floppy disk
|
||||
ComputerCraft.Items.disk = new ItemDisk(defaultItem().maxCount(1));
|
||||
ComputerCraft.Items.treasureDisk = new ItemTreasureDisk(defaultItem().maxCount(1));
|
||||
|
||||
public static final RegistryObject<BlockWiredModemFull> WIRED_MODEM_FULL = BLOCKS.register( "wired_modem_full",
|
||||
() -> new BlockWiredModemFull( modemProperties() ) );
|
||||
public static final RegistryObject<BlockCable> CABLE = BLOCKS.register( "cable", () -> new BlockCable( modemProperties() ) );
|
||||
}
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "disk"), ComputerCraft.Items.disk);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "treasure_disk"), ComputerCraft.Items.treasureDisk);
|
||||
|
||||
public static class ModTiles
|
||||
{
|
||||
static final DeferredRegister<BlockEntityType<?>> TILES = DeferredRegister.create( ForgeRegistries.TILE_ENTITIES, ComputerCraft.MOD_ID );
|
||||
// Printouts
|
||||
ComputerCraft.Items.printedPage = new ItemPrintout(defaultItem().maxCount(1), ItemPrintout.Type.PAGE);
|
||||
ComputerCraft.Items.printedPages = new ItemPrintout(defaultItem().maxCount(1), ItemPrintout.Type.PAGES);
|
||||
ComputerCraft.Items.printedBook = new ItemPrintout(defaultItem().maxCount(1), ItemPrintout.Type.BOOK);
|
||||
|
||||
private static <T extends BlockEntity> RegistryObject<BlockEntityType<T>> ofBlock( RegistryObject<? extends Block> block, Function<BlockEntityType<T>, T> factory )
|
||||
{
|
||||
return TILES.register( block.getId().getPath(), () -> FixedPointTileEntityType.create( block, factory ) );
|
||||
}
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "printed_page"), ComputerCraft.Items.printedPage);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "printed_pages"), ComputerCraft.Items.printedPages);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "printed_book"), ComputerCraft.Items.printedBook);
|
||||
|
||||
public static final RegistryObject<BlockEntityType<TileMonitor>> MONITOR_NORMAL =
|
||||
ofBlock( ModBlocks.MONITOR_NORMAL, f -> new TileMonitor( f, false ) );
|
||||
public static final RegistryObject<BlockEntityType<TileMonitor>> MONITOR_ADVANCED =
|
||||
ofBlock( ModBlocks.MONITOR_ADVANCED, f -> new TileMonitor( f, true ) );
|
||||
// Peripherals
|
||||
registerItemBlock(registry, new BlockItem(ComputerCraft.Blocks.speaker, defaultItem()));
|
||||
registerItemBlock(registry, new BlockItem(ComputerCraft.Blocks.diskDrive, defaultItem()));
|
||||
registerItemBlock(registry, new BlockItem(ComputerCraft.Blocks.printer, defaultItem()));
|
||||
registerItemBlock(registry, new BlockItem(ComputerCraft.Blocks.monitorNormal, defaultItem()));
|
||||
registerItemBlock(registry, new BlockItem(ComputerCraft.Blocks.monitorAdvanced, defaultItem()));
|
||||
registerItemBlock(registry, new BlockItem(ComputerCraft.Blocks.wirelessModemNormal, defaultItem()));
|
||||
registerItemBlock(registry, new BlockItem(ComputerCraft.Blocks.wirelessModemAdvanced, defaultItem()));
|
||||
registerItemBlock(registry, new BlockItem(ComputerCraft.Blocks.wiredModemFull, defaultItem()));
|
||||
|
||||
public static final RegistryObject<BlockEntityType<TileComputer>> COMPUTER_NORMAL =
|
||||
ofBlock( ModBlocks.COMPUTER_NORMAL, f -> new TileComputer( ComputerFamily.NORMAL, f ) );
|
||||
public static final RegistryObject<BlockEntityType<TileComputer>> COMPUTER_ADVANCED =
|
||||
ofBlock( ModBlocks.COMPUTER_ADVANCED, f -> new TileComputer( ComputerFamily.ADVANCED, f ) );
|
||||
public static final RegistryObject<BlockEntityType<TileCommandComputer>> COMPUTER_COMMAND =
|
||||
ofBlock( ModBlocks.COMPUTER_COMMAND, f -> new TileCommandComputer( ComputerFamily.COMMAND, f ) );
|
||||
ComputerCraft.Items.cable = new ItemBlockCable.Cable(ComputerCraft.Blocks.cable, defaultItem());
|
||||
ComputerCraft.Items.wiredModem = new ItemBlockCable.WiredModem(ComputerCraft.Blocks.cable, defaultItem());
|
||||
|
||||
public static final RegistryObject<BlockEntityType<TileTurtle>> TURTLE_NORMAL =
|
||||
ofBlock( ModBlocks.TURTLE_NORMAL, f -> new TileTurtle( f, ComputerFamily.NORMAL ) );
|
||||
public static final RegistryObject<BlockEntityType<TileTurtle>> TURTLE_ADVANCED =
|
||||
ofBlock( ModBlocks.TURTLE_ADVANCED, f -> new TileTurtle( f, ComputerFamily.ADVANCED ) );
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "cable"), ComputerCraft.Items.cable);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "wired_modem"), ComputerCraft.Items.wiredModem);
|
||||
|
||||
public static final RegistryObject<BlockEntityType<TileSpeaker>> SPEAKER = ofBlock( ModBlocks.SPEAKER, TileSpeaker::new );
|
||||
public static final RegistryObject<BlockEntityType<TileDiskDrive>> DISK_DRIVE = ofBlock( ModBlocks.DISK_DRIVE, TileDiskDrive::new );
|
||||
public static final RegistryObject<BlockEntityType<TilePrinter>> PRINTER = ofBlock( ModBlocks.PRINTER, TilePrinter::new );
|
||||
public static final RegistryObject<BlockEntityType<TileWiredModemFull>> WIRED_MODEM_FULL = ofBlock( ModBlocks.WIRED_MODEM_FULL, TileWiredModemFull::new );
|
||||
public static final RegistryObject<BlockEntityType<TileCable>> CABLE = ofBlock( ModBlocks.CABLE, TileCable::new );
|
||||
|
||||
public static final RegistryObject<BlockEntityType<TileWirelessModem>> WIRELESS_MODEM_NORMAL =
|
||||
ofBlock( ModBlocks.WIRELESS_MODEM_NORMAL, f -> new TileWirelessModem( f, false ) );
|
||||
public static final RegistryObject<BlockEntityType<TileWirelessModem>> WIRELESS_MODEM_ADVANCED =
|
||||
ofBlock( ModBlocks.WIRELESS_MODEM_ADVANCED, f -> new TileWirelessModem( f, true ) );
|
||||
}
|
||||
|
||||
public static final class ModItems
|
||||
{
|
||||
static final DeferredRegister<Item> ITEMS = DeferredRegister.create( ForgeRegistries.ITEMS, ComputerCraft.MOD_ID );
|
||||
|
||||
private static Item.Settings properties()
|
||||
{
|
||||
return new Item.Settings().group( mainItemGroup );
|
||||
}
|
||||
|
||||
private static <B extends Block, I extends Item> RegistryObject<I> ofBlock( RegistryObject<B> parent, BiFunction<B, Item.Settings, I> supplier )
|
||||
{
|
||||
return ITEMS.register( parent.getId().getPath(), () -> supplier.apply( parent.get(), properties() ) );
|
||||
}
|
||||
|
||||
public static final RegistryObject<ItemComputer> COMPUTER_NORMAL = ofBlock( ModBlocks.COMPUTER_NORMAL, ItemComputer::new );
|
||||
public static final RegistryObject<ItemComputer> COMPUTER_ADVANCED = ofBlock( ModBlocks.COMPUTER_ADVANCED, ItemComputer::new );
|
||||
public static final RegistryObject<ItemComputer> COMPUTER_COMMAND = ofBlock( ModBlocks.COMPUTER_COMMAND, ItemComputer::new );
|
||||
|
||||
public static final RegistryObject<ItemPocketComputer> POCKET_COMPUTER_NORMAL = ITEMS.register( "pocket_computer_normal",
|
||||
() -> new ItemPocketComputer( properties().maxCount( 1 ), ComputerFamily.NORMAL ) );
|
||||
public static final RegistryObject<ItemPocketComputer> POCKET_COMPUTER_ADVANCED = ITEMS.register( "pocket_computer_advanced",
|
||||
() -> new ItemPocketComputer( properties().maxCount( 1 ), ComputerFamily.ADVANCED ) );
|
||||
|
||||
public static final RegistryObject<ItemTurtle> TURTLE_NORMAL = ofBlock( ModBlocks.TURTLE_NORMAL, ItemTurtle::new );
|
||||
public static final RegistryObject<ItemTurtle> TURTLE_ADVANCED = ofBlock( ModBlocks.TURTLE_ADVANCED, ItemTurtle::new );
|
||||
|
||||
public static final RegistryObject<ItemDisk> DISK =
|
||||
ITEMS.register( "disk", () -> new ItemDisk( properties().maxCount( 1 ) ) );
|
||||
public static final RegistryObject<ItemTreasureDisk> TREASURE_DISK =
|
||||
ITEMS.register( "treasure_disk", () -> new ItemTreasureDisk( properties().maxCount( 1 ) ) );
|
||||
|
||||
public static final RegistryObject<ItemPrintout> PRINTED_PAGE = ITEMS.register( "printed_page",
|
||||
() -> new ItemPrintout( properties().maxCount( 1 ), ItemPrintout.Type.PAGE ) );
|
||||
public static final RegistryObject<ItemPrintout> PRINTED_PAGES = ITEMS.register( "printed_pages",
|
||||
() -> new ItemPrintout( properties().maxCount( 1 ), ItemPrintout.Type.PAGES ) );
|
||||
public static final RegistryObject<ItemPrintout> PRINTED_BOOK = ITEMS.register( "printed_book",
|
||||
() -> new ItemPrintout( properties().maxCount( 1 ), ItemPrintout.Type.BOOK ) );
|
||||
|
||||
public static final RegistryObject<BlockItem> SPEAKER = ofBlock( ModBlocks.SPEAKER, BlockItem::new );
|
||||
public static final RegistryObject<BlockItem> DISK_DRIVE = ofBlock( ModBlocks.DISK_DRIVE, BlockItem::new );
|
||||
public static final RegistryObject<BlockItem> PRINTER = ofBlock( ModBlocks.PRINTER, BlockItem::new );
|
||||
public static final RegistryObject<BlockItem> MONITOR_NORMAL = ofBlock( ModBlocks.MONITOR_NORMAL, BlockItem::new );
|
||||
public static final RegistryObject<BlockItem> MONITOR_ADVANCED = ofBlock( ModBlocks.MONITOR_ADVANCED, BlockItem::new );
|
||||
public static final RegistryObject<BlockItem> WIRELESS_MODEM_NORMAL = ofBlock( ModBlocks.WIRELESS_MODEM_NORMAL, BlockItem::new );
|
||||
public static final RegistryObject<BlockItem> WIRELESS_MODEM_ADVANCED = ofBlock( ModBlocks.WIRELESS_MODEM_ADVANCED, BlockItem::new );
|
||||
public static final RegistryObject<BlockItem> WIRED_MODEM_FULL = ofBlock( ModBlocks.WIRED_MODEM_FULL, BlockItem::new );
|
||||
|
||||
public static final RegistryObject<ItemBlockCable.Cable> CABLE = ITEMS.register( "cable",
|
||||
() -> new ItemBlockCable.Cable( ModBlocks.CABLE.get(), properties() ) );
|
||||
public static final RegistryObject<ItemBlockCable.WiredModem> WIRED_MODEM = ITEMS.register( "wired_modem",
|
||||
() -> new ItemBlockCable.WiredModem( ModBlocks.CABLE.get(), properties() ) );
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerItems( RegistryEvent.Register<Item> event )
|
||||
{
|
||||
registerTurtleUpgrades();
|
||||
registerPocketUpgrades();
|
||||
}
|
||||
|
||||
private static void registerTurtleUpgrades()
|
||||
{
|
||||
private static Item.Settings defaultItem() {
|
||||
return new Item.Settings().group(mainItemGroup);
|
||||
}
|
||||
|
||||
private static void registerItemBlock(MutableRegistry<Item> registry, BlockItem item) {
|
||||
registry.add(net.minecraft.util.registry.Registry.BLOCK.getId(item.getBlock()), item);
|
||||
}
|
||||
|
||||
private static void registerTurtleUpgrades() {
|
||||
// Upgrades
|
||||
ComputerCraft.TurtleUpgrades.wirelessModemNormal = new TurtleModem(false, new Identifier(ComputerCraft.MOD_ID, "wireless_modem_normal"));
|
||||
TurtleUpgrades.register( ComputerCraft.TurtleUpgrades.wirelessModemNormal );
|
||||
ComputerCraftAPI.registerTurtleUpgrade(ComputerCraft.TurtleUpgrades.wirelessModemNormal);
|
||||
|
||||
ComputerCraft.TurtleUpgrades.wirelessModemAdvanced = new TurtleModem(true, new Identifier(ComputerCraft.MOD_ID, "wireless_modem_advanced"));
|
||||
ComputerCraftAPI.registerTurtleUpgrade(ComputerCraft.TurtleUpgrades.wirelessModemAdvanced);
|
||||
@@ -272,74 +291,21 @@ public final class Registry
|
||||
ComputerCraftAPI.registerTurtleUpgrade(ComputerCraft.TurtleUpgrades.diamondHoe);
|
||||
}
|
||||
|
||||
private static void registerPocketUpgrades()
|
||||
{
|
||||
private static void registerPocketUpgrades() {
|
||||
ComputerCraftAPI.registerPocketUpgrade(ComputerCraft.PocketUpgrades.wirelessModemNormal = new PocketModem(false));
|
||||
ComputerCraftAPI.registerPocketUpgrade(ComputerCraft.PocketUpgrades.wirelessModemAdvanced = new PocketModem(true));
|
||||
ComputerCraftAPI.registerPocketUpgrade(ComputerCraft.PocketUpgrades.speaker = new PocketSpeaker());
|
||||
}
|
||||
|
||||
public static class ModEntities
|
||||
{
|
||||
static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create( ForgeRegistries.ENTITIES, ComputerCraft.MOD_ID );
|
||||
|
||||
public static final RegistryObject<EntityType<TurtlePlayer>> TURTLE_PLAYER = ENTITIES.register( "turtle_player", () ->
|
||||
EntityType.Builder.<TurtlePlayer>create( SpawnGroup.MISC )
|
||||
.disableSaving()
|
||||
.disableSummon()
|
||||
.setDimensions( 0, 0 )
|
||||
.build( ComputerCraft.MOD_ID + ":turtle_player" ) );
|
||||
}
|
||||
|
||||
public static class ModContainers
|
||||
{
|
||||
static final DeferredRegister<ScreenHandlerType<?>> CONTAINERS = DeferredRegister.create( ForgeRegistries.CONTAINERS, ComputerCraft.MOD_ID );
|
||||
|
||||
public static final RegistryObject<ScreenHandlerType<ContainerComputer>> COMPUTER = CONTAINERS.register( "computer",
|
||||
() -> ContainerData.toType( ComputerContainerData::new, ContainerComputer::new ) );
|
||||
|
||||
public static final RegistryObject<ScreenHandlerType<ContainerPocketComputer>> POCKET_COMPUTER = CONTAINERS.register( "pocket_computer",
|
||||
() -> ContainerData.toType( ComputerContainerData::new, ContainerPocketComputer::new ) );
|
||||
|
||||
public static final RegistryObject<ScreenHandlerType<ContainerTurtle>> TURTLE = CONTAINERS.register( "turtle",
|
||||
() -> ContainerData.toType( ComputerContainerData::new, ContainerTurtle::new ) );
|
||||
|
||||
public static final RegistryObject<ScreenHandlerType<ContainerDiskDrive>> DISK_DRIVE = CONTAINERS.register( "disk_drive",
|
||||
() -> new ScreenHandlerType<>( ContainerDiskDrive::new ) );
|
||||
|
||||
public static final RegistryObject<ScreenHandlerType<ContainerPrinter>> PRINTER = CONTAINERS.register( "printer",
|
||||
() -> new ScreenHandlerType<>( ContainerPrinter::new ) );
|
||||
|
||||
public static final RegistryObject<ScreenHandlerType<ContainerHeldItem>> PRINTOUT = CONTAINERS.register( "printout",
|
||||
() -> ContainerData.toType( HeldItemContainerData::new, ContainerHeldItem::createPrintout ) );
|
||||
|
||||
public static final RegistryObject<ScreenHandlerType<ContainerViewComputer>> VIEW_COMPUTER = CONTAINERS.register( "view_computer",
|
||||
() -> ContainerData.toType( ViewComputerContainerData::new, ContainerViewComputer::new ) );
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerRecipeSerializers( RegistryEvent.Register<RecipeSerializer<?>> event )
|
||||
{
|
||||
event.getRegistry().registerAll(
|
||||
ColourableRecipe.SERIALIZER.setRegistryName( new Identifier( ComputerCraft.MOD_ID, "colour" ) ),
|
||||
ComputerUpgradeRecipe.SERIALIZER.setRegistryName( new Identifier( ComputerCraft.MOD_ID, "computer_upgrade" ) ),
|
||||
PocketComputerUpgradeRecipe.SERIALIZER.setRegistryName( new Identifier( ComputerCraft.MOD_ID, "pocket_computer_upgrade" ) ),
|
||||
DiskRecipe.SERIALIZER.setRegistryName( new Identifier( ComputerCraft.MOD_ID, "disk" ) ),
|
||||
PrintoutRecipe.SERIALIZER.setRegistryName( new Identifier( ComputerCraft.MOD_ID, "printout" ) ),
|
||||
TurtleRecipe.SERIALIZER.setRegistryName( new Identifier( ComputerCraft.MOD_ID, "turtle" ) ),
|
||||
TurtleUpgradeRecipe.SERIALIZER.setRegistryName( new Identifier( ComputerCraft.MOD_ID, "turtle_upgrade" ) ),
|
||||
ImpostorShapelessRecipe.SERIALIZER.setRegistryName( new Identifier( ComputerCraft.MOD_ID, "impostor_shapeless" ) ),
|
||||
ImpostorRecipe.SERIALIZER.setRegistryName( new Identifier( ComputerCraft.MOD_ID, "impostor_shaped" ) )
|
||||
);
|
||||
}
|
||||
|
||||
public static void setup()
|
||||
{
|
||||
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
ModBlocks.BLOCKS.register( bus );
|
||||
ModTiles.TILES.register( bus );
|
||||
ModItems.ITEMS.register( bus );
|
||||
ModEntities.ENTITIES.register( bus );
|
||||
ModContainers.CONTAINERS.register( bus );
|
||||
public static void registerRecipes(MutableRegistry<RecipeSerializer<?>> registry) {
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "colour"), ColourableRecipe.SERIALIZER);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "computer_upgrade"), ComputerUpgradeRecipe.SERIALIZER);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "pocket_computer_upgrade"), PocketComputerUpgradeRecipe.SERIALIZER);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "disk"), DiskRecipe.SERIALIZER);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "printout"), PrintoutRecipe.SERIALIZER);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "turtle"), TurtleRecipe.SERIALIZER);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "turtle_upgrade"), TurtleUpgradeRecipe.SERIALIZER);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "impostor_shaped"), ImpostorRecipe.SERIALIZER);
|
||||
registry.add(new Identifier(ComputerCraft.MOD_ID, "impostor_shapeless"), ImpostorShapelessRecipe.SERIALIZER);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user