mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-06 16:33:00 +00:00
Switch to Forge's DeferredRegister
Well, mostly. We currently don't do recipe serializers as I'm a little too lazy. For items, blocks and TE types this does make registration nicer - we've some helper functions which help reduce duplication. Some types (containers, TEs, etc..) are a little less nice, as we now must define the registry object (i.e. the WhateverType<?>) in a separate class to the class it constructs. However, it's probably a worthwhile price to pay.
This commit is contained in:
@@ -12,7 +12,6 @@ import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.turtle.core.TurtleBrain;
|
||||
import dan200.computercraft.shared.turtle.items.ITurtleItem;
|
||||
import dan200.computercraft.shared.turtle.items.TurtleItemFactory;
|
||||
import dan200.computercraft.shared.util.NamedTileEntityType;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
@@ -28,6 +27,7 @@ import net.minecraft.state.DirectionProperty;
|
||||
import net.minecraft.state.StateContainer;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -36,6 +36,7 @@ import net.minecraft.util.math.shapes.ISelectionContext;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.util.math.shapes.VoxelShapes;
|
||||
import net.minecraft.world.*;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -52,7 +53,7 @@ public class BlockTurtle extends BlockComputerBase<TileTurtle> implements IWater
|
||||
0.875, 0.875, 0.875
|
||||
);
|
||||
|
||||
public BlockTurtle( Properties settings, ComputerFamily family, NamedTileEntityType<TileTurtle> type )
|
||||
public BlockTurtle( Properties settings, ComputerFamily family, RegistryObject<? extends TileEntityType<? extends TileTurtle>> type )
|
||||
{
|
||||
super( settings, family, type );
|
||||
setDefaultState( getStateContainer().getBaseState()
|
||||
@@ -70,7 +71,7 @@ public class BlockTurtle extends BlockComputerBase<TileTurtle> implements IWater
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public BlockRenderType getRenderType( BlockState state )
|
||||
public BlockRenderType getRenderType( @Nonnull BlockState state )
|
||||
{
|
||||
return BlockRenderType.ENTITYBLOCK_ANIMATED;
|
||||
}
|
||||
@@ -78,7 +79,7 @@ public class BlockTurtle extends BlockComputerBase<TileTurtle> implements IWater
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public VoxelShape getShape( BlockState state, IBlockReader world, BlockPos pos, ISelectionContext context )
|
||||
public VoxelShape getShape( @Nonnull BlockState state, IBlockReader world, @Nonnull BlockPos pos, @Nonnull ISelectionContext context )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
Vec3d offset = tile instanceof TileTurtle ? ((TileTurtle) tile).getRenderOffset( 1.0f ) : Vec3d.ZERO;
|
||||
@@ -97,7 +98,7 @@ public class BlockTurtle extends BlockComputerBase<TileTurtle> implements IWater
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public IFluidState getFluidState( BlockState state )
|
||||
public IFluidState getFluidState( @Nonnull BlockState state )
|
||||
{
|
||||
return getWaterloggedFluidState( state );
|
||||
}
|
||||
@@ -105,14 +106,14 @@ public class BlockTurtle extends BlockComputerBase<TileTurtle> implements IWater
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public BlockState updatePostPlacement( @Nonnull BlockState state, Direction side, BlockState otherState, IWorld world, BlockPos pos, BlockPos otherPos )
|
||||
public BlockState updatePostPlacement( @Nonnull BlockState state, @Nonnull Direction side, @Nonnull BlockState otherState, @Nonnull IWorld world, @Nonnull BlockPos pos, @Nonnull BlockPos otherPos )
|
||||
{
|
||||
updateWaterloggedPostPlacement( state, world, pos );
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy( World world, BlockPos pos, BlockState state, @Nullable LivingEntity player, @Nonnull ItemStack stack )
|
||||
public void onBlockPlacedBy( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable LivingEntity player, @Nonnull ItemStack stack )
|
||||
{
|
||||
super.onBlockPlacedBy( world, pos, state, player, stack );
|
||||
|
||||
|
||||
@@ -56,16 +56,6 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
public static final int INVENTORY_WIDTH = 4;
|
||||
public static final int INVENTORY_HEIGHT = 4;
|
||||
|
||||
public static final NamedTileEntityType<TileTurtle> FACTORY_NORMAL = NamedTileEntityType.create(
|
||||
new ResourceLocation( ComputerCraft.MOD_ID, "turtle_normal" ),
|
||||
type -> new TileTurtle( type, ComputerFamily.NORMAL )
|
||||
);
|
||||
|
||||
public static final NamedTileEntityType<TileTurtle> FACTORY_ADVANCED = NamedTileEntityType.create(
|
||||
new ResourceLocation( ComputerCraft.MOD_ID, "turtle_advanced" ),
|
||||
type -> new TileTurtle( type, ComputerFamily.ADVANCED )
|
||||
);
|
||||
|
||||
enum MoveState
|
||||
{
|
||||
NOT_MOVED,
|
||||
@@ -266,7 +256,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read( CompoundNBT nbt )
|
||||
public void read( @Nonnull CompoundNBT nbt )
|
||||
{
|
||||
super.read( nbt );
|
||||
|
||||
@@ -291,7 +281,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompoundNBT write( CompoundNBT nbt )
|
||||
public CompoundNBT write( @Nonnull CompoundNBT nbt )
|
||||
{
|
||||
// Write inventory
|
||||
ListNBT nbttaglist = new ListNBT();
|
||||
|
||||
@@ -8,10 +8,14 @@ package dan200.computercraft.shared.turtle.core;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||
import dan200.computercraft.shared.Registry;
|
||||
import dan200.computercraft.shared.util.FakeNetHandler;
|
||||
import dan200.computercraft.shared.util.InventoryUtil;
|
||||
import dan200.computercraft.shared.util.WorldUtil;
|
||||
import net.minecraft.entity.*;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntitySize;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.Pose;
|
||||
import net.minecraft.entity.passive.horse.AbstractHorseEntity;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
@@ -37,12 +41,6 @@ public final class TurtlePlayer extends FakePlayer
|
||||
"[ComputerCraft]"
|
||||
);
|
||||
|
||||
public static final EntityType<TurtlePlayer> TYPE = EntityType.Builder.<TurtlePlayer>create( EntityClassification.MISC )
|
||||
.disableSerialization()
|
||||
.disableSummoning()
|
||||
.size( 0, 0 )
|
||||
.build( ComputerCraft.MOD_ID + ":turtle_player" );
|
||||
|
||||
private TurtlePlayer( ITurtleAccess turtle )
|
||||
{
|
||||
super( (ServerWorld) turtle.getWorld(), getProfile( turtle.getOwningPlayer() ) );
|
||||
@@ -129,7 +127,7 @@ public final class TurtlePlayer extends FakePlayer
|
||||
@Override
|
||||
public EntityType<?> getType()
|
||||
{
|
||||
return TYPE;
|
||||
return Registry.ModEntities.TURTLE_PLAYER.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -145,7 +143,7 @@ public final class TurtlePlayer extends FakePlayer
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getStandingEyeHeight( Pose pose, EntitySize size )
|
||||
public float getStandingEyeHeight( @Nonnull Pose pose, @Nonnull EntitySize size )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -180,17 +178,17 @@ public final class TurtlePlayer extends FakePlayer
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openSignEditor( SignTileEntity signTile )
|
||||
public void openSignEditor( @Nonnull SignTileEntity signTile )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openHorseInventory( AbstractHorseEntity horse, IInventory inventory )
|
||||
public void openHorseInventory( @Nonnull AbstractHorseEntity horse, @Nonnull IInventory inventory )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openBook( ItemStack stack, @Nonnull Hand hand )
|
||||
public void openBook( @Nonnull ItemStack stack, @Nonnull Hand hand )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -205,17 +203,17 @@ public final class TurtlePlayer extends FakePlayer
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewPotionEffect( EffectInstance id )
|
||||
protected void onNewPotionEffect( @Nonnull EffectInstance id )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onChangedPotionEffect( EffectInstance id, boolean apply )
|
||||
protected void onChangedPotionEffect( @Nonnull EffectInstance id, boolean apply )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishedPotionEffect( EffectInstance effect )
|
||||
protected void onFinishedPotionEffect( @Nonnull EffectInstance effect )
|
||||
{
|
||||
}
|
||||
//endregion
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
*/
|
||||
package dan200.computercraft.shared.turtle.inventory;
|
||||
|
||||
import dan200.computercraft.shared.Registry;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.IComputer;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerComputerBase;
|
||||
import dan200.computercraft.shared.network.container.ComputerContainerData;
|
||||
import dan200.computercraft.shared.network.container.ContainerData;
|
||||
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
||||
import dan200.computercraft.shared.turtle.core.TurtleBrain;
|
||||
import dan200.computercraft.shared.util.SingleIntArray;
|
||||
@@ -17,7 +17,6 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIntArray;
|
||||
@@ -28,8 +27,6 @@ import java.util.function.Predicate;
|
||||
|
||||
public class ContainerTurtle extends ContainerComputerBase
|
||||
{
|
||||
public static final ContainerType<ContainerTurtle> TYPE = ContainerData.toType( ComputerContainerData::new, ContainerTurtle::new );
|
||||
|
||||
public static final int PLAYER_START_Y = 134;
|
||||
public static final int TURTLE_START_X = 175;
|
||||
|
||||
@@ -40,7 +37,7 @@ public class ContainerTurtle extends ContainerComputerBase
|
||||
PlayerInventory playerInventory, IInventory inventory, IIntArray properties
|
||||
)
|
||||
{
|
||||
super( TYPE, id, canUse, computer, family );
|
||||
super( Registry.ModContainers.TURTLE.get(), id, canUse, computer, family );
|
||||
this.properties = properties;
|
||||
|
||||
trackIntArray( properties );
|
||||
@@ -78,7 +75,7 @@ public class ContainerTurtle extends ContainerComputerBase
|
||||
);
|
||||
}
|
||||
|
||||
private ContainerTurtle( int id, PlayerInventory player, ComputerContainerData data )
|
||||
public ContainerTurtle( int id, PlayerInventory player, ComputerContainerData data )
|
||||
{
|
||||
this(
|
||||
id, x -> true, getComputer( player, data ), data.getFamily(),
|
||||
@@ -128,7 +125,7 @@ public class ContainerTurtle extends ContainerComputerBase
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack transferStackInSlot( PlayerEntity player, int slotNum )
|
||||
public ItemStack transferStackInSlot( @Nonnull PlayerEntity player, int slotNum )
|
||||
{
|
||||
if( slotNum >= 0 && slotNum < 16 )
|
||||
{
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
*/
|
||||
package dan200.computercraft.shared.turtle.items;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||
import dan200.computercraft.api.turtle.TurtleSide;
|
||||
import dan200.computercraft.shared.Registry;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.turtle.blocks.ITurtleTile;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -38,9 +38,9 @@ public final class TurtleItemFactory
|
||||
switch( family )
|
||||
{
|
||||
case NORMAL:
|
||||
return ComputerCraft.Items.turtleNormal.create( id, label, colour, leftUpgrade, rightUpgrade, fuelLevel, overlay );
|
||||
return Registry.ModItems.TURTLE_NORMAL.get().create( id, label, colour, leftUpgrade, rightUpgrade, fuelLevel, overlay );
|
||||
case ADVANCED:
|
||||
return ComputerCraft.Items.turtleAdvanced.create( id, label, colour, leftUpgrade, rightUpgrade, fuelLevel, overlay );
|
||||
return Registry.ModItems.TURTLE_ADVANCED.get().create( id, label, colour, leftUpgrade, rightUpgrade, fuelLevel, overlay );
|
||||
default:
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsableByPlayer( PlayerEntity player )
|
||||
public boolean isUsableByPlayer( @Nonnull PlayerEntity player )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
*/
|
||||
package dan200.computercraft.shared.turtle.upgrades;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.client.TransformedModel;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.api.turtle.*;
|
||||
import dan200.computercraft.shared.Registry;
|
||||
import dan200.computercraft.shared.peripheral.modem.ModemState;
|
||||
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessModemPeripheral;
|
||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
||||
@@ -61,7 +61,7 @@ public class TurtleModem extends AbstractTurtleUpgrade
|
||||
}
|
||||
}
|
||||
|
||||
private boolean advanced;
|
||||
private final boolean advanced;
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
private ModelResourceLocation m_leftOffModel;
|
||||
@@ -80,8 +80,8 @@ public class TurtleModem extends AbstractTurtleUpgrade
|
||||
super(
|
||||
id, TurtleUpgradeType.PERIPHERAL,
|
||||
advanced
|
||||
? ComputerCraft.Blocks.wirelessModemAdvanced
|
||||
: ComputerCraft.Blocks.wirelessModemNormal
|
||||
? Registry.ModBlocks.WIRELESS_MODEM_ADVANCED
|
||||
: Registry.ModBlocks.WIRELESS_MODEM_NORMAL
|
||||
);
|
||||
this.advanced = advanced;
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
|
||||
package dan200.computercraft.shared.turtle.upgrades;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.client.TransformedModel;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.api.turtle.AbstractTurtleUpgrade;
|
||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||
import dan200.computercraft.api.turtle.TurtleSide;
|
||||
import dan200.computercraft.api.turtle.TurtleUpgradeType;
|
||||
import dan200.computercraft.shared.Registry;
|
||||
import dan200.computercraft.shared.peripheral.speaker.SpeakerPeripheral;
|
||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -63,7 +63,7 @@ public class TurtleSpeaker extends AbstractTurtleUpgrade
|
||||
|
||||
public TurtleSpeaker( ResourceLocation id )
|
||||
{
|
||||
super( id, TurtleUpgradeType.PERIPHERAL, ComputerCraft.Blocks.speaker );
|
||||
super( id, TurtleUpgradeType.PERIPHERAL, Registry.ModBlocks.SPEAKER );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user