Commit Graph

29 Commits

Author SHA1 Message Date
iceiix 518b6a07f8
Reformat all source with cargo fmt (#335) 2020-06-21 12:17:24 -07:00
iceiix 87e0726f3f
blocks: split macro into multiple functions, fast! (#267)
Improves fix for #184, whereas #255 reduced optimizations,
we now address the underlying compiler limitation and split out
the one massive lazy_static! initialization function, into
one function per block in the block_registration_functions module.

Previous build time, with opt-level=1:

% time cargo build --release
   Compiling steven_blocks v0.0.1
    Finished release [optimized] target(s) in 21.24s
cargo build --release  31.80s user 0.71s system 152% cpu 21.276 total

With this change, opt-level=3 and the function splitting fix:

% time cargo build --release
   Compiling steven_blocks v0.0.1
    Finished release [optimized] target(s) in 30.80s
cargo build --release  40.26s user 0.86s system 133% cpu 30.850 total

Full optimizations are expectedly slightly slower, but this is still
much much _much_ faster than before this refactoring, where this crate
would take up to an unbelievable 5 hours (and tens of GB of RAM). Long
story short, we're now back to full optimizations and stable Rust.

Thanks to dtolnay on the Rust programming language forum for suggesting
this technique, https://users.rust-lang.org/t/5-hours-to-compile-macro-what-can-i-do/36508/2
2020-01-09 20:08:28 -08:00
ice_iix d729039849 steven_blocks: Use the ? operator instead of * in macro
Previously, only the * and + operators were available, for 0 or more and
1 or more, respectively, so steven_blocks used * for optional tokens
even though only one would be expected in most cases.

Rust version 1.32.0 added a new operator, ?, for zero or one:

https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1320-2019-01-17
> You can now use the ? operator in macro definitions. The ? operator allows
> you to specify zero or one repetitions similar to the * and + operators.
https://github.com/rust-lang/rust/pull/56245/

Change to use ? instead of * for these optional repetitions.
Found this while investigating #174.
2019-05-30 18:31:23 -07:00
ice_iix fd028d41b0 Replace println! with log crate facade macros info!, debug!, etc. 2019-05-22 16:01:14 -07:00
iceiix e9b336192a Add support for a modded block: rockwool from Thermal Expansion (#153)
The first in support for modded content, a simple custom block: "rockwool" from the Thermal Expansion and Thermal Foundation mods for Forge:

https://ftb.gamepedia.com/Rockwool_(Thermal_Expansion_3)

This makes use of the Forge handshake (#88 #134 #144), matching the mod block names from the negotiation to numeric identifiers in the world to steven_blocks. Rockwool was chosen due to ease of implementation, it looks like wool from vanilla (except is fire-proof), and by supporting it the groundwork necessary is laid for more sophisticated mod support.

Tested with Thermal Expansion on 1.7.10, 1.10.2 (FTB Beyond), and 1.12.2 Forge servers.

* Add `modid` macro token, skipped from vanilla mappings

* Add ThermalExpansionRockwool block (1.7.10)

* Register modded blocks by modid->[data], and lookup block metadata

* Save block IDs from ModIdData/RegistryData to World modded_block_ids

* Add namespaced mod ids for ModIdData, \u{1}=block \u{2}=item

* Add ThermalFoundation's Rockwool (1.12.2)
2019-05-15 12:49:57 -07:00
ice_iix 67841f9b2e Fix missing pre-flattening blocks (deadbush, etc.). Closes #89
Blocks not present after "the flattening" (1.13.2) were not registered
for older versions (hierarchical, pre-1.13). This wasn't noticed when
implementing #67 since almost all blocks pre-flattening also have
flattened IDs. The exceptions are when the blocks were removed or moved,
such as dead bush - hierarchical id 32, which is now a block state of
tallgrass instead. But it is still needed pre-flattening, due a logic
error these were skipped.

Fix pre-flattening block ID registration by moving the conditional
clause for vanilla_id outside of the offset conditional.
2019-01-12 10:40:57 -08:00
iceiix 11f2d2ae13 1.13.2 (404) multiprotocol support (#67)
Adds support for 1.13.2 protocol (404)
Expands https://github.com/iceiix/steven/issues/18 Enhance protocol support

Metadata:

* Support 1.13.2 slot data format, bool and varint item id, optional damage (moved to NBT)

https://wiki.vg/index.php?title=Slot_Data&type=revision&diff=14363&oldid=7835

Packets:

* Add 1.13.2 packets, and implement all the command data parsers

https://wiki.vg/Command_Data#Parsers

* Send new plugin channel minecraft:brand

https://wiki.vg/Plugin_channels#minecraft:brand

* Add 1.13.2 metadata format, with shifted IDs

https://wiki.vg/Entity_metadata#Entity_Metadata_Format

* Implement particle entity metadata

* Add structures for 16 new packets

Blocks: The Flattening:

* Assign flattened IDs in correct order using new 'offset' macro token

* Assign hierarchical (pre-flattening) block IDs sequentially by counting Some data

* Split VANILLA_ID_MAP into flat/hier struct, to support before and after the flattening

* Extend travis build time to 20 minutes because the blocks macro takes a long time

* Support both flat/hier blocks by passing protocol_version to by_vanilla_id

Add block states and offsets for all blocks, replacing metadata for 1.13+:

* Add stripped logs and what was Log2 to Log
* Add the Wood blocks, should be called bark, previously Axis::None Log
* Add leaves distance and offset
* Add jungle/acacia to Leaves moved from Leaves2
* Add dispenser offsets, direction
* Add note block states
* Add offset None to Missing253 and Missing254, no holes in block states of 1.13.2
* Add bed colors
* Add seagrass, tall seagrass, remove redundant deadgrass, and piston offset
* Add torch, TNT, fire offsets, remove slabs
* Add furnance offset, merges lit into a property
* Add pressure plate offsets, new pressure plates, redstone ore/lit merged
* Add lever offsets, new directions from ceiling/floor, rename LeverDirections
* Add redstone torch offsets, new blocks since lit/unlit is now merged, and standing/wall is split
* Change lever to split face/facing, rm LeverDirection, add AttachedFace
* Add stone button offsets, face/facing similar to lever
* Move face/facing data and variant to AttachedFace, reuse for lever/stonebutton
* Add data_with_facing_and_powered() to AttachedFace, for lever/stonebutton
* Add wooden button offsets each wood
* Add pumpkin without a face
* Add carved pumpkin, portal offsets
* Add lit pumpkin (as jack-o-lantern) offsets after carved pumpkin
* Add repeater offsets, merged into Repeater
* Change brown mushroom block to booleans instead of MushroomVariant
* Add mushroom block offsets, red/brown mushroom blocks, and a new mushroom stem block
* Add command block, cobblestone walls, and flower pot offsets
Empty flower pot, and potted plants including saplings. Rename
variant DarkOak to DarkOakSaplings because it is a sapling, and
remove the duplicate Dandelion variant which causes duplicate blocks.
* Increase recursion limit in steven_blocks
* Add colored banner offsets
* Add wooden slab including double slab, in a different position for pre-1.13 and 1.13
* StoneSlabVariant::Wood -> StoneSlabVariant::PetrifiedWood
* Add fence_gate_offset() for wooden fence gates
* Add frosted ice age, offset
* Add new blocks: kelp, turtle egg, coral, coral fans, sea pickle, blue ice, smooth stone
* Add new blocks: conduit, void air, cave aid, bubble column, last of the 1.13 blocks
2018-12-28 21:22:58 -08:00
iceiix bf8d913d19
Add new blocks up to 1.12 (#68)
* Add observer block
Added in 1.11: https://minecraft.gamepedia.com/Observer

* Add shulker box blocks, using wool for models for now
Added in 1.12: https://minecraft.gamepedia.com/Shulker_Box

* Add glazed terracotta
Added in 1.12: https://minecraft.gamepedia.com/Glazed_Terracotta

* Add concrete and concrete powder
Both were added in 1.12:
https://minecraft.gamepedia.com/Concrete
https://minecraft.gamepedia.com/Concrete_Powder

* Add structure block
https://minecraft.gamepedia.com/Structure_Block
2018-12-22 14:34:06 -08:00
iceiix 797b20aaf9
Add new blocks up to 1.10 (#69)
* Update blocks/Cargo.lock

* Add magma block

Turns out magma was added way back in 1.10: https://minecraft.gamepedia.com/Magma_Block

* Add nether wart block and red nether brick

Both were added in 1.10:
https://minecraft.gamepedia.com/Nether_Wart_Block
https://minecraft.gamepedia.com/Nether_Bricks#History

* Add bone blocks

Added in 1.10, and they have orientation similar to logs:
https://minecraft.gamepedia.com/Bone_Block

* Add structure void

Added in 1.10, invisible but not a barrier:
https://minecraft.gamepedia.com/Structure_Block#Structure_void
2018-12-17 19:20:51 -08:00
ice_iix 9b31646a8d Disable three stylistic Clippy warnings, var names/params, never loop
This allows the tool to continue and emit a bunch more warnings
2018-11-04 15:01:44 -08:00
ice_iix d111497a50 Use if let instead of match to fix clippy warning 2018-11-04 14:39:08 -08:00
ice_iix b4514a8500 Fix clippy warnings: passed by reference, but would be more efficient if passed by value
https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#trivially_copy_pass_by_ref

i = 0
ll = map(lambda x: int(x.strip()), file("/tmp/lines").readlines())
ll2 = map(lambda x: int(x.strip()), file("/tmp/lines2").readlines())
for line in file("/Users/admin/games/rust/steven/blocks/src/lib.rs").readlines():
    i += 1
    line = line[:-1]

    if i in ll:
        line = line.replace("&self", "self")

    if i in ll2:
        line = line.replace("*self", "self")

    print line
2018-11-04 14:31:46 -08:00
ice_iix ca14ea595b Fix clippy warnings: casting u8 to f64 may become silently lossy if types change
https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#cast_lossless
2018-11-04 14:21:10 -08:00
ice_iix 411e4f69a6 Remove unnecessary 'extern crate's in Rust 2018 edition, import macros
https://rust-lang-nursery.github.io/edition-guide/print.html#no-more-extern-crate
https://rust-lang-nursery.github.io/edition-guide/rust-2018/macros/macro-changes.html
https://github.com/iceiix/steven/pull/13#issuecomment-435702507
2018-11-04 12:39:23 -08:00
ice_iix 0d8696286c Update Cargo.tomls to Rust edition 2018, fix crate imports. Closes #13 2018-11-04 12:15:34 -08:00
ice_iix be46377842 Remove unused macros and imports to appease compiler warnings
https://github.com/iceiix/steven/issues/1
2018-09-29 23:52:47 -07:00
Thinkofname 2cc00f086b Implement collisions for stairs 2016-04-21 22:39:34 +01:00
Thinkofname 287867dbcd Add a collidable flag to Material 2016-04-21 21:47:39 +01:00
Thinkofname 1c898b594e Fix door collisions 2016-04-21 20:57:50 +01:00
Thinkofname bb5032fd30 Remove the steven_id system 2016-04-20 21:52:04 +01:00
Scetch 7588b20bd0 Block fixes and some cleanup. 2016-04-20 14:54:32 -04:00
Scetch dab2c3fc89 Default block material to solid. 2016-04-13 10:50:08 -04:00
Thinkofname a7c586b2e9 Optimize the types used for blocks.
Reduces the size of a block from 16 bytes -> 8 bytes on my 64 bit machine.
2016-04-09 13:48:42 +01:00
Scetch 64ec2e4d3b Cleaning up blocks a little bit. 2016-04-08 11:30:41 -04:00
Scetch b037fb1e5c Fix layered snow collision 2016-04-07 14:55:47 -04:00
Thinkofname c117f28b2a Block entity support, implement signs 2016-04-04 22:08:24 +01:00
Scetch 7c31332dc8 Implement more block collisions. 2016-04-03 23:55:20 -04:00
Thinkofname 98ecd348c6 Replace usages of x,y,z for block positions with Position 2016-04-03 20:53:40 +01:00
Thinkofname 92d773bd72 Move blocks into its own crate to speed up compile times 2016-04-03 18:26:52 +01:00
Renamed from src/world/block/mod.rs (Browse further)