From e8d7e6a562a1cef4d93b3e224031e4086200a9bb Mon Sep 17 00:00:00 2001 From: SquidDev Date: Thu, 25 Apr 2019 11:18:02 +0100 Subject: [PATCH] Fix a whole bunch of bugs --- build.gradle | 6 +-- gradle.properties | 2 +- .../computercraft/client/ClientRegistry.java | 47 ++++--------------- .../computercraft/client/gui/GuiComputer.java | 11 +++++ .../computercraft/client/gui/GuiTurtle.java | 22 +++++++++ .../proxy/ComputerCraftProxyClient.java | 8 ++++ .../shared/mixin/MixinBlock.java | 34 ++++++++++++++ .../shared/mixin/MixinEntity.java | 33 +++++++++++++ .../shared/mixin/MixinServerWorld.java | 28 +++++++++++ .../turtle/core/TurtlePlaceCommand.java | 5 +- .../shared/turtle/upgrades/TurtleTool.java | 11 +++-- .../shared/util/DropConsumer.java | 43 ++++++++--------- .../shared/util/ItemStorage.java | 42 ++++++++--------- .../computercraft/shared/util/WorldUtil.java | 22 +++++++-- src/main/resources/computercraft.common.json | 13 +++++ .../recipes/computer_advanced.json | 2 +- .../advancements/recipes/computer_normal.json | 2 +- src/main/resources/fabric.mod.json | 3 +- 18 files changed, 233 insertions(+), 101 deletions(-) create mode 100644 src/main/java/dan200/computercraft/shared/mixin/MixinBlock.java create mode 100644 src/main/java/dan200/computercraft/shared/mixin/MixinEntity.java create mode 100644 src/main/java/dan200/computercraft/shared/mixin/MixinServerWorld.java create mode 100644 src/main/resources/computercraft.common.json diff --git a/build.gradle b/build.gradle index a25677ebd..f6cd0fd95 100644 --- a/build.gradle +++ b/build.gradle @@ -189,7 +189,7 @@ processResources { inputs.property "commithash", hash from(sourceSets.main.resources.srcDirs) { - include 'fabric.mods.json' + include 'fabric.mod.json' include 'data/computercraft/lua/rom/help/credits.txt' expand 'version': mod_version, @@ -198,7 +198,7 @@ processResources { } from(sourceSets.main.resources.srcDirs) { - exclude 'fabric.mods.json' + exclude 'fabric.mod.json' exclude 'data/computercraft/lua/rom/help/credits.txt' } } @@ -250,7 +250,7 @@ curseforge { project { id = '282001' addGameVersion '1.14-Snapshot' - releaseType = 'alpha' + releaseType = 'beta' changelog = "Release notes can be found on the GitHub repository (https://github.com/SquidDev-CC/CC-Tweaked/releases/tag/v${mc_version}-${mod_version})." } } diff --git a/gradle.properties b/gradle.properties index 2aca66a6a..146d66068 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # Mod properties -mod_version=1.82.3 +mod_version=1.82.4 # Minecraft properties mc_version=1.14 diff --git a/src/main/java/dan200/computercraft/client/ClientRegistry.java b/src/main/java/dan200/computercraft/client/ClientRegistry.java index 6ebb1bb4d..c151fcb3d 100644 --- a/src/main/java/dan200/computercraft/client/ClientRegistry.java +++ b/src/main/java/dan200/computercraft/client/ClientRegistry.java @@ -12,14 +12,19 @@ import dan200.computercraft.shared.media.items.ItemDisk; import dan200.computercraft.shared.pocket.items.ItemPocketComputer; import dan200.computercraft.shared.util.Colour; import net.fabricmc.fabric.api.client.render.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.util.Identifier; import java.util.HashSet; +import java.util.function.Consumer; /** * Registers textures and models for items. @@ -57,55 +62,21 @@ public final class ClientRegistry private ClientRegistry() {} - /* - TODO: @SubscribeEvent - public static void registerModels( ModelRegistryEvent event ) + public static void onTextureStitchEvent( SpriteAtlasTexture atlasTexture, ClientSpriteRegistryCallback.Registry registry ) { - ModelLoaderRegistry.registerLoader( TurtleModelLoader.INSTANCE ); - } - - TODO: @SubscribeEvent - public static void onTextureStitchEvent( TextureStitchEvent.Pre event ) - { - ResourceManager manager = MinecraftClient.getInstance().getResourceManager(); for( String extra : EXTRA_TEXTURES ) { - event.getMap().registerSprite( manager, new Identifier( ComputerCraft.MOD_ID, extra ) ); + registry.register( new Identifier( ComputerCraft.MOD_ID, extra ) ); } } - TODO: @SubscribeEvent - public static void onModelBakeEvent( ModelBakeEvent event ) + public static void onModelBakeEvent( ResourceManager manager, Consumer out ) { - // Load all extra models - ModelLoader loader = event.getModelLoader(); - Map registry = event.getModelRegistry(); - for( String model : EXTRA_MODELS ) { - BakedModel bakedModel = bake( loader, loader.getOrLoadModel( new Identifier( ComputerCraft.MOD_ID, "item/" + model ) ) ); - - if( bakedModel != null ) - { - registry.put( - new ModelIdentifier( new Identifier( ComputerCraft.MOD_ID, model ), "inventory" ), - bakedModel - ); - } + out.accept( new ModelIdentifier( new Identifier( ComputerCraft.MOD_ID, model ), "inventory" ) ); } - - // And load the custom turtle models in too. - registry.put( - new ModelIdentifier( new Identifier( ComputerCraft.MOD_ID, "turtle_normal" ), "inventory" ), - bake( loader, TurtleModelLoader.INSTANCE.loadModel( new Identifier( ComputerCraft.MOD_ID, "item/turtle_normal" ) ) ) - ); - - registry.put( - new ModelIdentifier( new Identifier( ComputerCraft.MOD_ID, "turtle_advanced" ), "inventory" ), - bake( loader, TurtleModelLoader.INSTANCE.loadModel( new Identifier( ComputerCraft.MOD_ID, "item/turtle_advanced" ) ) ) - ); } - */ public static void onItemColours() { diff --git a/src/main/java/dan200/computercraft/client/gui/GuiComputer.java b/src/main/java/dan200/computercraft/client/gui/GuiComputer.java index 44183e2e6..3d437c858 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiComputer.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiComputer.java @@ -19,6 +19,7 @@ import net.minecraft.container.Container; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.text.StringTextComponent; import net.minecraft.util.Identifier; +import org.lwjgl.glfw.GLFW; public class GuiComputer extends ContainerScreen { @@ -141,9 +142,18 @@ public class GuiComputer extends ContainerScreen drawMouseoverTooltip( mouseX, mouseY ); } + @Override + public boolean keyPressed( int key, int scancode, int modifiers ) + { + // When pressing tab, send it to the computer first + return (key == GLFW.GLFW_KEY_TAB && getFocused() == terminalWrapper && terminalWrapper.keyPressed( key, scancode, modifiers )) + || super.keyPressed( key, scancode, modifiers ); + } + @Override public boolean mouseDragged( double x, double y, int button, double deltaX, double deltaY ) { + // Make sure drag events are propagated to children return (getFocused() != null && getFocused().mouseDragged( x, y, button, deltaX, deltaY )) || super.mouseDragged( x, y, button, deltaX, deltaY ); } @@ -151,6 +161,7 @@ public class GuiComputer extends ContainerScreen @Override public boolean mouseReleased( double x, double y, int button ) { + // Make sure release events are propagated to children return (getFocused() != null && getFocused().mouseReleased( x, y, button )) || super.mouseReleased( x, y, button ); } diff --git a/src/main/java/dan200/computercraft/client/gui/GuiTurtle.java b/src/main/java/dan200/computercraft/client/gui/GuiTurtle.java index 018220c31..49ede4cab 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiTurtle.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiTurtle.java @@ -17,6 +17,7 @@ import dan200.computercraft.shared.turtle.inventory.ContainerTurtle; import net.minecraft.client.gui.ContainerScreen; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.util.Identifier; +import org.lwjgl.glfw.GLFW; public class GuiTurtle extends ContainerScreen { @@ -116,4 +117,25 @@ public class GuiTurtle extends ContainerScreen super.render( mouseX, mouseY, partialTicks ); drawMouseoverTooltip( mouseX, mouseY ); } + + @Override + public boolean keyPressed( int key, int scancode, int modifiers ) + { + return (key == GLFW.GLFW_KEY_TAB && getFocused() == terminalWrapper && terminalWrapper.keyPressed( key, scancode, modifiers )) + || super.keyPressed( key, scancode, modifiers ); + } + + @Override + public boolean mouseDragged( double x, double y, int button, double deltaX, double deltaY ) + { + return (getFocused() != null && getFocused().mouseDragged( x, y, button, deltaX, deltaY )) + || super.mouseDragged( x, y, button, deltaX, deltaY ); + } + + @Override + public boolean mouseReleased( double x, double y, int button ) + { + return (getFocused() != null && getFocused().mouseReleased( x, y, button )) + || super.mouseReleased( x, y, button ); + } } diff --git a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java index 7c676fb71..63c0ed324 100644 --- a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java +++ b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java @@ -12,6 +12,7 @@ import dan200.computercraft.client.gui.*; import dan200.computercraft.client.render.TileEntityCableRenderer; import dan200.computercraft.client.render.TileEntityMonitorRenderer; import dan200.computercraft.client.render.TileEntityTurtleRenderer; +import dan200.computercraft.client.render.TurtleModelLoader; import dan200.computercraft.shared.computer.blocks.TileComputer; import dan200.computercraft.shared.computer.core.ClientComputer; import dan200.computercraft.shared.computer.inventory.ContainerViewComputer; @@ -20,7 +21,9 @@ import dan200.computercraft.shared.peripheral.modem.wired.TileCable; import dan200.computercraft.shared.peripheral.monitor.TileMonitor; import dan200.computercraft.shared.turtle.blocks.TileTurtle; import dan200.computercraft.shared.turtle.inventory.ContainerTurtle; +import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry; import net.fabricmc.fabric.api.client.render.BlockEntityRendererRegistry; +import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback; public final class ComputerCraftProxyClient { @@ -34,6 +37,11 @@ public final class ComputerCraftProxyClient BlockEntityRendererRegistry.INSTANCE.register( TileTurtle.class, new TileEntityTurtleRenderer() ); ClientRegistry.onItemColours(); + ClientSpriteRegistryCallback.registerBlockAtlas( ClientRegistry::onTextureStitchEvent ); + ModelLoadingRegistry.INSTANCE.registerAppender( ClientRegistry::onModelBakeEvent ); + ModelLoadingRegistry.INSTANCE.registerResourceProvider( loader -> ( name, context ) -> + TurtleModelLoader.INSTANCE.accepts( name ) ? TurtleModelLoader.INSTANCE.loadModel( name ) : null + ); } private static void registerContainers() diff --git a/src/main/java/dan200/computercraft/shared/mixin/MixinBlock.java b/src/main/java/dan200/computercraft/shared/mixin/MixinBlock.java new file mode 100644 index 000000000..47846b59c --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/mixin/MixinBlock.java @@ -0,0 +1,34 @@ +/* + * This file is part of ComputerCraft - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. + * Send enquiries to dratcliffe@gmail.com + */ + +package dan200.computercraft.shared.mixin; + +import dan200.computercraft.shared.util.DropConsumer; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +/** + * @see Block#dropStack(World, BlockPos, ItemStack) + */ +@Mixin( Block.class ) +public class MixinBlock +{ + @Inject( + method = "dropStack", + at = @At( value = "INVOKE", target = "Lnet/minecraft/world/World;spawnEntity(Lnet/minecraft/entity/Entity;)Z" ), + cancellable = true + ) + private static void dropStack( World world, BlockPos pos, ItemStack stack, CallbackInfo callbackInfo ) + { + if( DropConsumer.onHarvestDrops( world, pos, stack ) ) callbackInfo.cancel(); + } +} diff --git a/src/main/java/dan200/computercraft/shared/mixin/MixinEntity.java b/src/main/java/dan200/computercraft/shared/mixin/MixinEntity.java new file mode 100644 index 000000000..7403d7216 --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/mixin/MixinEntity.java @@ -0,0 +1,33 @@ +/* + * This file is part of ComputerCraft - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. + * Send enquiries to dratcliffe@gmail.com + */ + +package dan200.computercraft.shared.mixin; + +import dan200.computercraft.shared.util.DropConsumer; +import net.minecraft.entity.Entity; +import net.minecraft.entity.ItemEntity; +import net.minecraft.item.ItemStack; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +/** + * @see Entity#dropStack(ItemStack, float) + */ +@Mixin( Entity.class ) +public class MixinEntity +{ + @Inject( + method = "dropStack(Lnet/minecraft/item/ItemStack;F)Lnet/minecraft/entity/ItemEntity;", + at = @At( value = "INVOKE", target = "Lnet/minecraft/world/World;spawnEntity(Lnet/minecraft/entity/Entity;)Z" ), + cancellable = true + ) + public void dropStack( ItemStack stack, float height, CallbackInfoReturnable callbackInfo ) + { + if( DropConsumer.onEntityLivingDrops( (Entity) (Object) this, stack ) ) callbackInfo.setReturnValue( null ); + } +} diff --git a/src/main/java/dan200/computercraft/shared/mixin/MixinServerWorld.java b/src/main/java/dan200/computercraft/shared/mixin/MixinServerWorld.java new file mode 100644 index 000000000..97195a9f3 --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/mixin/MixinServerWorld.java @@ -0,0 +1,28 @@ +/* + * This file is part of ComputerCraft - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. + * Send enquiries to dratcliffe@gmail.com + */ + +package dan200.computercraft.shared.mixin; + +import dan200.computercraft.shared.util.DropConsumer; +import net.minecraft.entity.Entity; +import net.minecraft.server.world.ServerWorld; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +/** + * @see ServerWorld#spawnEntity(Entity) + */ +@Mixin( ServerWorld.class ) +public class MixinServerWorld +{ + @Inject( method = "spawnEntity", at = @At( "HEAD" ), cancellable = true ) + public void spawnEntity( Entity entity, CallbackInfoReturnable callbackInfo ) + { + if( DropConsumer.onEntitySpawn( entity ) ) callbackInfo.setReturnValue( false ); + } +} diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java index 282a4f363..9971f83cd 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java @@ -286,9 +286,8 @@ public class TurtlePlaceCommand implements ITurtleCommand private static boolean canDeployOnBlock( @Nonnull ItemPlacementContext context, ITurtleAccess turtle, TurtlePlayer player, BlockPos position, Direction side, boolean allowReplaceable, String[] outErrorMessage ) { World world = turtle.getWorld(); - if( World.isValid( position ) && - !world.isAir( position ) && - !(context.getItemStack().getItem() instanceof BlockItem && WorldUtil.isLiquidBlock( world, position )) ) + if( !World.isValid( position ) || world.isAir( position ) || + (context.getItemStack().getItem() instanceof BlockItem && WorldUtil.isLiquidBlock( world, position )) ) { return false; } diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java index 496df29bb..e47255504 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java @@ -21,6 +21,7 @@ import dan200.computercraft.shared.util.ItemStorage; import dan200.computercraft.shared.util.WorldUtil; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.event.player.AttackEntityCallback; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -33,6 +34,8 @@ import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.decoration.ArmorStandEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -99,8 +102,7 @@ public class TurtleTool extends AbstractTurtleUpgrade Block block = state.getBlock(); return !state.isAir() && block != Blocks.BEDROCK - && state.getHardness( world, pos ) > 0 - /*&& block.canEntityDestroy( state, world, pos, player )*/; + && state.calcBlockBreakingDelta( player, world, pos ) > 0; } protected float getDamageMultiplier() @@ -128,12 +130,11 @@ public class TurtleTool extends AbstractTurtleUpgrade Entity hitEntity = hit.getKey(); // Fire several events to ensure we have permissions. - /* - if( MinecraftForge.EVENT_BUS.post( new AttackEntityEvent( turtlePlayer, hitEntity ) ) || !hitEntity.canBeAttackedWithItem() ) + if( AttackEntityCallback.EVENT.invoker().interact( turtlePlayer, world, Hand.MAIN, hitEntity, null ) == ActionResult.FAIL + || !hitEntity.canPlayerAttack() ) { return TurtleCommandResult.failure( "Nothing to attack here" ); } - */ TurtleAttackEvent attackEvent = new TurtleAttackEvent( turtle, turtlePlayer, hitEntity, this, side ); if( TurtleEvent.post( attackEvent ) ) diff --git a/src/main/java/dan200/computercraft/shared/util/DropConsumer.java b/src/main/java/dan200/computercraft/shared/util/DropConsumer.java index 11d682c14..4b69cced8 100644 --- a/src/main/java/dan200/computercraft/shared/util/DropConsumer.java +++ b/src/main/java/dan200/computercraft/shared/util/DropConsumer.java @@ -7,6 +7,7 @@ package dan200.computercraft.shared.util; import net.minecraft.entity.Entity; +import net.minecraft.entity.ItemEntity; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BoundingBox; @@ -87,44 +88,40 @@ public final class DropConsumer if( !remaining.isEmpty() ) remainingDrops.add( remaining ); } - /* - @SubscribeEvent( priority = EventPriority.LOWEST ) - public static void onEntityLivingDrops( LivingDropsEvent event ) + public static boolean onEntityLivingDrops( Entity entity, ItemStack stack ) { // Capture any mob drops for the current entity - if( dropEntity != null && event.getEntity() == dropEntity.get() ) + if( dropEntity != null && entity == dropEntity.get() ) { - Collection drops = event.getDrops(); - for( EntityItem entityItem : drops ) handleDrops( entityItem.getItem() ); - drops.clear(); + handleDrops( stack ); + return true; } + + return false; } - @SubscribeEvent( priority = EventPriority.LOWEST ) - public static void onHarvestDrops( BlockEvent.HarvestDropsEvent event ) + public static boolean onHarvestDrops( World world, BlockPos pos, ItemStack stack ) { // Capture block drops for the current entity - if( dropWorld != null && dropWorld.get() == event.getWorld() - && dropPos != null && dropPos.equals( event.getPos() ) ) + if( dropWorld != null && dropWorld.get() == world && dropPos != null && dropPos.equals( pos ) ) { - for( ItemStack item : event.getDrops() ) - { - if( event.getWorld().getRandom().nextFloat() < event.getDropChance() ) handleDrops( item ); - } - event.getDrops().clear(); + handleDrops( stack ); + return true; } + + return false; } - @SubscribeEvent( priority = EventPriority.LOWEST ) - public static void onEntitySpawn( EntityJoinWorldEvent event ) + public static boolean onEntitySpawn( Entity entity ) { // Capture any nearby item spawns - if( dropWorld != null && dropWorld.get() == event.getWorld() && event.getEntity() instanceof EntityItem - && dropBounds.contains( event.getEntity().getPositionVector() ) ) + if( dropWorld != null && dropWorld.get() == entity.getEntityWorld() && entity instanceof ItemEntity + && dropBounds.contains( entity.getPos() ) ) { - handleDrops( ((EntityItem) event.getEntity()).getItem() ); - event.setCanceled( true ); + handleDrops( ((ItemEntity) entity).getStack() ); + return true; } + + return false; } - */ } diff --git a/src/main/java/dan200/computercraft/shared/util/ItemStorage.java b/src/main/java/dan200/computercraft/shared/util/ItemStorage.java index 4400147d5..0f99c4289 100644 --- a/src/main/java/dan200/computercraft/shared/util/ItemStorage.java +++ b/src/main/java/dan200/computercraft/shared/util/ItemStorage.java @@ -6,6 +6,7 @@ package dan200.computercraft.shared.util; +import dan200.computercraft.ComputerCraft; import net.minecraft.inventory.Inventory; import net.minecraft.inventory.SidedInventory; import net.minecraft.item.ItemStack; @@ -58,8 +59,8 @@ public interface ItemStorage } @Override - public @Nonnull - ItemStack take( int slot, int limit, @Nonnull ItemStack filter, boolean simulate ) + @Nonnull + public ItemStack take( int slot, int limit, @Nonnull ItemStack filter, boolean simulate ) { ItemStack existing = inventory.getInvStack( slot ); if( existing.isEmpty() || !canExtract( slot, existing ) @@ -88,8 +89,8 @@ public interface ItemStorage } @Override - public @Nonnull - ItemStack store( int slot, @Nonnull ItemStack stack, boolean simulate ) + @Nonnull + public ItemStack store( int slot, @Nonnull ItemStack stack, boolean simulate ) { if( stack.isEmpty() || !inventory.isValidInvStack( slot, stack ) ) return stack; @@ -97,7 +98,7 @@ public interface ItemStorage if( existing.isEmpty() ) { int limit = Math.min( stack.getMaxAmount(), inventory.getInvMaxStackAmount() ); - if( limit <= 0 ) return ItemStack.EMPTY; + if( limit <= 0 ) return stack; if( stack.getAmount() < limit ) { @@ -114,8 +115,8 @@ public interface ItemStorage } else if( areStackable( stack, existing ) ) { - int limit = Math.min( existing.getMaxAmount(), inventory.getInvMaxStackAmount() ) - stack.getAmount(); - if( limit <= 0 ) return ItemStack.EMPTY; + int limit = Math.min( existing.getMaxAmount(), inventory.getInvMaxStackAmount() ) - existing.getAmount(); + if( limit <= 0 ) return stack; if( stack.getAmount() < limit ) { @@ -140,7 +141,7 @@ public interface ItemStorage } else { - return ItemStack.EMPTY; + return stack; } } } @@ -169,24 +170,23 @@ public interface ItemStorage return super.canExtract( slot, stack ) && inventory.canExtractInvStack( slot, stack, facing ); } + @Nonnull @Override - public @Nonnull - ItemStack take( int slot, int limit, @Nonnull ItemStack filter, boolean simulate ) + public ItemStack take( int slot, int limit, @Nonnull ItemStack filter, boolean simulate ) { int[] slots = inventory.getInvAvailableSlots( facing ); return slot >= 0 && slot < slots.length ? super.take( slots[slot], limit, filter, simulate ) : ItemStack.EMPTY; - } + @Nonnull @Override - public @Nonnull - ItemStack store( int slot, @Nonnull ItemStack stack, boolean simulate ) + public ItemStack store( int slot, @Nonnull ItemStack stack, boolean simulate ) { int[] slots = inventory.getInvAvailableSlots( facing ); - if( slot < 0 || slot >= slots.length ) return ItemStack.EMPTY; + if( slot < 0 || slot >= slots.length ) return stack; int mappedSlot = slots[slot]; - if( !inventory.canInsertInvStack( slot, stack, facing ) ) return ItemStack.EMPTY; + if( !inventory.canInsertInvStack( slot, stack, facing ) ) return stack; return super.store( mappedSlot, stack, simulate ); } } @@ -197,7 +197,7 @@ public interface ItemStorage private final int start; private final int size; - public View( ItemStorage parent, int start, int size ) + View( ItemStorage parent, int start, int size ) { this.parent = parent; this.start = start; @@ -210,19 +210,19 @@ public interface ItemStorage return size; } + @Nonnull @Override - public @Nonnull - ItemStack take( int slot, int limit, @Nonnull ItemStack filter, boolean simulate ) + public ItemStack take( int slot, int limit, @Nonnull ItemStack filter, boolean simulate ) { if( slot < start || slot >= start + size ) return ItemStack.EMPTY; return parent.take( slot - start, limit, filter, simulate ); } + @Nonnull @Override - public @Nonnull - ItemStack store( int slot, @Nonnull ItemStack stack, boolean simulate ) + public ItemStack store( int slot, @Nonnull ItemStack stack, boolean simulate ) { - if( slot < start || slot >= start + size ) return ItemStack.EMPTY; + if( slot < start || slot >= start + size ) return stack; return parent.store( slot - start, stack, simulate ); } diff --git a/src/main/java/dan200/computercraft/shared/util/WorldUtil.java b/src/main/java/dan200/computercraft/shared/util/WorldUtil.java index bbfeae5d9..586bae203 100644 --- a/src/main/java/dan200/computercraft/shared/util/WorldUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/WorldUtil.java @@ -8,9 +8,7 @@ package dan200.computercraft.shared.util; import com.google.common.base.Predicate; import net.minecraft.block.BlockState; -import net.minecraft.entity.Entity; -import net.minecraft.entity.ItemEntity; -import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.*; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.util.hit.HitResult; @@ -31,6 +29,21 @@ public final class WorldUtil @SuppressWarnings( "Guava" ) private static final Predicate CAN_COLLIDE = x -> x != null && x.isAlive() && x.collides(); + private static final Entity ENTITY = new ItemEntity( EntityType.ITEM, null ) + { + @Override + public EntitySize getSize( EntityPose pos ) + { + return EntitySize.constant( 0, 0 ); + } + }; + + static + { + ENTITY.noClip = true; + ENTITY.refreshSize(); + } + public static boolean isLiquidBlock( World world, BlockPos pos ) { if( !World.isValid( pos ) ) return false; @@ -51,7 +64,8 @@ public final class WorldUtil Vec3d vecEnd = vecStart.add( vecDir.x * distance, vecDir.y * distance, vecDir.z * distance ); // Raycast for blocks - HitResult result = world.rayTrace( new RayTraceContext( vecStart, vecEnd, RayTraceContext.ShapeType.OUTLINE, RayTraceContext.FluidHandling.NONE, null ) ); + ENTITY.setPosition( vecStart.x, vecStart.y, vecStart.z ); + HitResult result = world.rayTrace( new RayTraceContext( vecStart, vecEnd, RayTraceContext.ShapeType.OUTLINE, RayTraceContext.FluidHandling.NONE, ENTITY ) ); if( result != null && result.getType() == HitResult.Type.BLOCK ) { distance = vecStart.distanceTo( result.getPos() ); diff --git a/src/main/resources/computercraft.common.json b/src/main/resources/computercraft.common.json new file mode 100644 index 000000000..746f83d16 --- /dev/null +++ b/src/main/resources/computercraft.common.json @@ -0,0 +1,13 @@ +{ + "required": true, + "package": "dan200.computercraft.shared.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "MixinBlock", + "MixinEntity", + "MixinServerWorld" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/src/main/resources/data/computercraft/advancements/recipes/computer_advanced.json b/src/main/resources/data/computercraft/advancements/recipes/computer_advanced.json index fa3783c51..96c0f57e4 100644 --- a/src/main/resources/data/computercraft/advancements/recipes/computer_advanced.json +++ b/src/main/resources/data/computercraft/advancements/recipes/computer_advanced.json @@ -7,7 +7,7 @@ "has_redstone": { "trigger": "minecraft:inventory_changed", "conditions": { - "items": [ { "tag": "forge:dusts/redstone" } ] + "items": [ { "item": "minecraft:redstone" } ] } }, "has_the_recipe": { diff --git a/src/main/resources/data/computercraft/advancements/recipes/computer_normal.json b/src/main/resources/data/computercraft/advancements/recipes/computer_normal.json index 1ad34028d..b8ef77055 100644 --- a/src/main/resources/data/computercraft/advancements/recipes/computer_normal.json +++ b/src/main/resources/data/computercraft/advancements/recipes/computer_normal.json @@ -7,7 +7,7 @@ "has_redstone": { "trigger": "minecraft:inventory_changed", "conditions": { - "items": [ { "tag": "forge:dusts/redstone" } ] + "items": [ { "item": "minecraft:redstone" } ] } }, "has_the_recipe": { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 995f52060..bbd58ce51 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -22,6 +22,7 @@ "main": [ "dan200.computercraft.ComputerCraft" ] }, "mixins": [ - { "config": "computercraft.client.json", "environment": "client" } + { "config": "computercraft.client.json", "environment": "client" }, + "computercraft.common.json" ] }