Commit Graph

57 Commits

Author SHA1 Message Date
Jonathan Coates 2fab1a3054
Minor code style fixups
- Add missing @Override annotations. I can't find a way to enforce this
   with checkstyle - maybe I need spotbugs too D:.
 - Remove superflous "this"es.
2021-06-12 22:18:35 +01:00
Jonathan Coates 9142ccfc93
Rewrite turtle placing logic
- Simplify how the turtle's inventory is processed. We now copy all
   items into the player inventory, attempt to place, and then copy the
   items back.

   This also fixes the problem where turtle.place() wouldn't (always)
   update the item which was placed.

   I'm also hoping this is more "correct" in how we process drops from
   entities and whatnot. Though I've not had any reports of issues, so
   it's probably fine.

 - Replace the "error message" string array with an actual object. It'd
   be nicer all these functions returned a TurtleCommandResult, but
   merging error messages from that is a little harder.

Fun facts: the test suite was actually helpful here, and caught the fact
that hoeing was broken!
2021-05-29 15:18:26 +01:00
Jonathan Coates 34b5ede326 Switch to Mojang mappings
ForgeGradle (probably sensibly) yells at me about doing this. However:
 - There's a reasonable number of mods doing this, which establishes
   some optimistic precedent.
 - The licence update in Aug 2020 now allows you to use them for
   "development purposes". I guess source code counts??
 - I'm fairly sure this is also compatible with the CCPL - there's an
   exception for Minecraft code.

The main motivation for this is to make the Fabric port a little
easier. Hopefully folks (maybe me in the future, we'll see) will no
longer have to deal with mapping hell when merging - only mod loader
hell.
2021-01-09 19:22:58 +00:00
Jonathan Coates e4b0a5b3ce 2020 -> 2021
Oh, the most useless part of my build process.
2021-01-06 17:13:40 +00:00
Jonathan Coates 2f0cae0bc1 Make upgrade recipe requirements a little more lax
- Move some common upgrade code to IUpgradeBase. 99% sure this this
   preserves binary compatibility (on the JVM at least).

 - Instead of requiring the share tag to match, allow upgrades to
   specify their own predicate. IMO this is a little ugly, but required
   to fix #614 as other mods chuck their own NBT on items.
2020-12-23 15:52:33 +00:00
SquidDev 24af36743d Try to handle a turtle being broken while ticked
Hopefully fixes #585. Hopefully.
2020-11-28 13:13:35 +00:00
SquidDev f3a330e330 Normalise enums to use SHOUTY_CASE
PascalCase is more .NET than Java
2020-01-28 22:28:48 +00:00
SquidDev 044d2b2b06 Some API cleanup
- Remove *Stream methods on IMount/IWritableMount, and make the channel
   ones the primary.
 - Fix location of AbstractTurtleUpgrade
 - Make IComputerAccess.getAvailablePeripheral and .getMainThreadMonitor
   mandatory.
 - IComputerAccess throws a specialised NotAttachedException
2020-01-28 22:23:43 +00:00
SquidDev fb440b0d2e Update to 1.15
Most of the port is pretty simple. The main problems are regarding
changes to Minecraft's rendering system.

 - Remove several rendering tweaks until Forge's compatibility it
   brought up-to-date
    - Map rendering for pocket computers and printouts
    - Item frame rendering for printouts
    - Custom block outlines for monitors and cables/wired modems
    - Custom breaking progress for cables/wired modems

 - Turtle "Dinnerbone" rendering is currently broken, as normals are not
   correctly transformed.

 - Rewrite FixedWidthFontRenderer to to the buffer in a single sweep.
   In order to do this, the term_font now also bundles a "background"
   section, which is just a blank region of the screen.

 - Render monitors using a VBO instead of a call list. I haven't
   compared performance yet, but it manages to render a 6x5 array of
   _static_ monitors at almost 60fps, which seems pretty reasonable.
2020-01-24 09:12:29 +00:00
SquidDev 41a1b99f7d Merge branch 'master' into mc-1.14.x 2020-01-13 15:05:50 +00:00
SquidDev 93a9ebc4f6 Happy new year 2020-01-01 00:09:18 +00:00
SquidDev 4320a4f851 Update CT integration
Sadly we have to disable -Werror, as the annotation class files are not
available on maven, so this produces a warning.
2019-12-24 19:16:06 +00:00
SquidDev 037cbabb32 Merge branch 'master' into mc-1.14.x
Unfortunately we can't apply the config changes due to backwards
compatibility. This'll be something we may need to PR into Forge.

CraftTweaker support still needs to be added.
2019-12-23 22:34:30 +00:00
Jonathan Coates 3a5d50e572
Basic Minetweaker support (#327)
This provides the following methods:

 - dan200.computercraft.turtle.removeUpgrade(id: String)
 - dan200.computercraft.turtle.removeUpgrade(stack: IItemStack)
 - dan200.computercraft.turtle.addTool(id: String, craftItem: IItemStack[, toolItem: IItemStack][, kind: string])

While it's pretty minimal, it should allow for a reasonable amount of
functionality.

Closes #327 and #97.
2019-12-18 15:29:24 +00:00
SquidDev 4b0e5c445c Merge branch 'master' into mc-1.14.x 2019-08-04 10:57:20 +01:00
powerboat9 303b57779a Fix turtles harvesting blocks when they shouldn't (#276)
harvestBlock should only be called when removedByPlayer and canHarvestBlock
return true, otherwise we run the risk of causing dupe bugs.

See #273.
2019-07-17 09:23:14 +01:00
SquidDev 39a9ad0ce7 Initial update to 1.14
So very little works, but it compiles and runs.

Things to resolve over the next few days:
 - Horrible mappings (should largely be resolved by tomorrow).
 - Cannot send extra data over containers - we'll have to see what Forge
   does here.
 - Turtle models are broken
 - No block drops yet - this will largely be cherry-picking whatever I
   did on Fabric.
 - Weird inventory desyncs (items don't show up initially when
   interacting with a CC inventory).
 - Probably lots of other things.
2019-06-08 13:36:31 +01:00
SquidDev 0f3c44c926 Merge branch 'master' into mc-1.13.x 2019-06-08 08:21:08 +01:00
SquidDev a0e7c4a74c Add a little bit of source code checking to Gradle
- Adds a CheckStyle configuration which is pretty similar to CC's
   existing one.
 - Add the Gradle license plugin.
 - Ensure the existing source code is compatible with these additional
   checks.

See #239
2019-06-08 00:28:03 +01:00
SquidDev f9e13ca67a Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.

Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:

 - Flatten everything. For instance, there are now three instances of
   BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
   more BlockPeripheral (thank heavens) - there's separate block classes
   for each peripheral type.

 - Remove pretty much all legacy code. As we're breaking world
   compatibility anyway, we can remove all the code to load worlds from
   1.4 days.
 - The command system is largely rewriten to take advantage of 1.13's
   new system. It's very fancy!

 - WidgetTerminal now uses Minecraft's "GUI listener" system.

 - BREAKING CHANGE: All the codes in keys.lua are different, due to the
   move to LWJGL 3. Hopefully this won't have too much of an impact.

   I don't want to map to the old key codes on the Java side, as there
   always ends up being small but slight inconsistencies. IMO it's
   better to make a clean break - people should be using keys rather
   than hard coding the constants anyway.

 - commands.list now allows fetching sub-commands. The ROM has already
   been updated to allow fancy usage such as commands.time.set("noon").

 - Turtles, modems and cables can be waterlogged.
2019-04-02 20:59:48 +01:00
SquidDev 2965fb666f Some further cleanup and 1.13 cherry-picks
Are most of these changes small and petty? Yes. However, IMO they do
make the code more readable. Anyway, a summary of some of the more
interesting changes:

 - Expose Abstract*Upgrade classes in the API
 - Fix the spelling of Jonathan in the API docs (*shakes fist*)
 - Fix bug with printout not working in the offhand.
 - Rename any argments/variables accidentally named "m_*", and add an
   inspection to prevent it happening again.
 - Remove most of the Block*.Properties classes - just inline them in
   the parent class.
 - Return super.writeToNBT instead of reassigning at the top.
2019-04-02 12:08:03 +01:00
SquidDev 173ea72001 Turn inspections up to 11
OK, so let's get this out of the way, there's some actual changes mixed
in here too. I'm really sorry:
 - Turtles can now not be renamed with unnamed item tags (previously it
   would clear the name, this seemed a little unideal).
 - commands.getBlock(s)Data will also include NBT.

Now, onto the horror story which is these inspection changes:
 - Make a lot of methods static
 - Typo fixes
 - Make utility classes final + private constructor
 - Lots of reformatting (ifs -> ternary, invert control flow, etc...)
 - ???
 - Profit!

I'm so going to regret this - can pretty much guarantee this is going to
break something.
2019-03-29 21:26:21 +00:00
SquidDev a838595e1e Derive upgrade adjectives from its ID
This is done in 1.13+ for items and blocks, so we might as well do it
for upgrades now. Note we can't do it for ender pocket modems, as the
upgrade ID is spelled incorrectly there.
2019-01-14 10:42:13 +00:00
SquidDev 5d97b9c8f3 Utilise @Mod.EventBusSubscriber a little more
This offers several advantages

 - Less registration code: the subscribers are reigstered automatically,
   and we don't need to worry about sided-proxies.
 - We no longer have so many .instance() calls.
2019-01-12 16:27:40 +00:00
SquidDev 1c9110b927 Happy new year! 2019-01-01 01:10:18 +00:00
SquidDev f8b328a048 Move drop consumer code into a separate class
This has always been separate from turtles, so there is no reason to
keep it there.
2018-12-28 12:47:44 +00:00
SquidDev 41a320e9a4 Move API registration into separate classes
There's several reasons for this change:
 - Try to make ComputerCraft.java less monolithic by moving
   functionality into separate module-specific classes.
 - Hopefully make the core class less Minecraft dependent, meaning
   emulators are a little less dependent on anything outside of /core.

Note we still need /some/ methods in the main ComputerCraft class in
order to maintain backwards compatibility with Plethora and
Computronics.
2018-12-28 12:40:33 +00:00
SquidDev 4ead319092 Remove direct support for beginner's turtles
As CCEdu has not been updated, and is unlikely to be updated as Dan does
not have the rights to open source it, we're removing explicit support
for now.

If an alternative arises in the future, it would be good to support, but
in a way which requires less workarounds in CC's core.
2018-12-26 09:13:15 +00:00
SquidDev dd6bab5413 Move some shared upgrade code into a base class
Most upgrades provides a couple of constant getters (upgrade ID,
adjective, crafting item). We move the getters into a parent class and
pass the values in via the constructor instead.

Also do a tiny bit of cleanup to the upgrades. Mostly just reducing
nesting, renaming fields, etc...
2018-12-26 09:01:03 +00:00
SquidDev 741ee447ca A wee bit of a cleanup of the API
- Move some method over to defaulted methods
 - Use Objects rather than Preconditions
2018-12-17 21:33:49 +00:00
apemanzilla 89c7183a1d Prevent stack overflows when using turtle.place() with a full inventory 2018-08-23 07:56:50 +01:00
SquidDev b8957cab5c Update to the latest mappings
This is a preliminary for updating to 1.13, as many of the name changes
apply to both. This will make it harder to remain consistent with
actual CC, though that will be less of a consideration when 1.13 hits.
2018-07-24 09:27:05 +01:00
SquidDev 000786a1a7 Merge pull request #560 from SquidDev-CC/ComputerCraft/hotfix/turtle-destroy
Rewrite turtle block destroying
2018-07-08 23:01:13 +01:00
SquidDev 45a189e834 Cache a turtle's fake player
Player construction can get a little expensive, and this is exacerbated
by Sponge. We now cache a turtle's fake player (updating the position
every time it is requested) in order to reduce this overhead.
2018-07-08 15:21:42 +01:00
SquidDev 4d984dc5ee Rewrite turtle block destroying
- Try to make drop capturing a little more generic. This now allows for
   capturing a block's drop at a given position, as well as any drop
   within a bounding box (for things which don't play nicely).

 - Use as much of Minecraft's block breaking logic as possible,
   hopefully simplifying things and making it more consistent with other
   mods.
2018-07-06 18:49:15 +01:00
SquidDev d3ecd5214b Merge remote-tracking branch 'SquidDev-CC-ComputerCraft/feature/turtle-event' 2018-02-16 10:48:43 +00:00
SquidDev ecff23d027 Add turtle events
The main aim of this is to allow for greater extensibility for other
mods. For instance, you can now prevent turtles placing dirt blocks, or
turning when on gravel.
2018-02-16 10:33:32 +00:00
SquidDev 41cce78fcb Merge pull request #518 from SquidDev-CC/ComputerCraft/feature/owner-tracking
Track which player "owns" a turtle
2018-02-05 11:07:06 +00:00
SquidDev 4c0fa1fabe Track which player "owns" a turtle
When a player places a turtle, they are marked as its owner. Any actions
they perform (such as breaking blocks, moving, etc...) are performed
using this player's game profile.

This allows turtles to work correctly with various permissions mods.
Previously you would have to whitelist all turtles in order for them to
function within a claim.
2018-02-04 21:35:21 +00:00
SquidDev 632762768e Add workaround for incorrect overload of getDrops being overridden
Closes #2
2017-12-30 19:03:32 +00:00
SquidDev d29ffed383 Java 8. Java 8. Does whatever Java 8 can.
Default methods, everywhere.
Arrow types, switch on strings.
Lambdas!
Here comes Java 8.
2017-07-25 21:10:48 +01:00
SquidDev 08099f08f2 Initial update to 1.12
- Convert most recipes to JSON
 - Add JSON factories for impostor and turtle recipes.
 - Several mappings changes
 - Migrate to Forge's new registry system
2017-07-25 21:10:47 +01:00
SquidDev 35425f0f61 Update to 1.11.2 2017-07-25 21:08:51 +01:00
SquidDev 255dc925fb Fire Forge events where appropriate
- BlockEvent.BreakEvent and BlockEvent.HarvestDropsEvent are fired when
   digging.
 - AttackEntityEvent is fired when attacking.
 - Various PlayerInteractEvent.* events are fired when placing.

Closes #103, closes #100
2017-05-31 12:41:31 +01:00
Daniel Ratcliffe 891666c8bf Merge pull request #220 from SquidDev-CC/feature/item-handler
Replace most inventory handling code with IItemHandlers
2017-05-13 21:31:58 +01:00
ObloxCC 7f754f33bb Updated (C) from 2016 to 2017 (#229)
* Updated (C)

* Fixed Whitespace

bugs, bugs, and more bugs

* Fixed Whitespaces 1/2

* Fixed Whitespaces 2/2

* Fixed Whitespaces 3/2
2017-05-13 19:20:39 +01:00
SquidDev b07f28c30c Replace most inventory handling code with IItemHandlers
- Make InventoryUtil deal with item handlers instead. This
   significantly simplifies the implementation, the interface now
   does most of the hard work.
 - Add InvWrapper item handlers to printers, disk drives and turtles
 - Add IItemHandlerModifiable accessor to ITurtleAccess
 - Migrate all other inventory code (mostly turtle commands) to use
   item handlers instead.
2017-05-11 00:00:10 +01:00
SquidDev 5a60818c99 Make many fields final 2017-05-07 13:35:18 +01:00
SquidDev a2fd0b1f7f Use block comment instead of Javadoc for license 2017-05-07 13:30:10 +01:00
SquidDev db9cd15fb3 Remove most raw types
This means we can remove even more casts and what not.
2017-05-07 13:30:05 +01:00