Skip to content

Commit

Permalink
Add support for custom blocks and skulls (#3505)
Browse files Browse the repository at this point in the history
* Super cursed custom skulls custom block

* Rename some stuff

* Attempt to clean up some code

* Remove skull translation events and define custom blocks for custom skulls

Clean up skull block translation a bit

* Auto generate skull resource pack

Change `davchoo` to `geyser` in geometry

* Add config options for custom blocks and custom skull blocks

* Fix formatting and names for player skulls

* Use block states more efficiently for custom skulls

21 block states vs 48 block states

* Clean up custom block api a bit

* Apply some suggestions from Camotoy

* Move custom skull config stuff to its own file

Custom skulls can now be added by username, uuid, and textures

Move skull nbt stuff from requestTexturesFromUsername to
SkullBlockEntityTranslator
Add requestTexturesFromUUID

* Update custom block nbt for v534

* Disable collision box & selection box when box is empty

Fix incorrect collision names used in CustomBlockComponentsBuilder

* Add custom block stuff to provider registry loader

* More API changes

Convert CustomBlockPermutation into a record
Change materialInstances in CustomBlockComponents Builder to
materialInstance
Reuse box components in CustomSkull

* Convert skull floor geometries into a template

Should be easier to modify in needed in the future.

* Crop and reorder skull textures to eliminate unused space

Should reduce memory & storage usage for Bedrock clients

* Revert "Crop and reorder skull textures to eliminate unused space"

This reverts commit 15fd535.

* Use identifier from CustomBlockData in SkullResourcePackManager

* Fix isIncorrectHeldItem check for custom skull blocks

Add defaultBlockState to CustomBlockData

* Fix adding duplicate block states for custom blocks with 0 properties

Remove defaultBlockState CustomBlockState field from
GeyserCustomBlockData since it creates a circular reference

* Add basis for overriding Bedrock block states

Fix missing providers when used in GeyserDefineCustomBlocksEvent

* Fix custom blocks in 1.19.50

* Decouple mappings from items

* Decouple mappings from items

* Null check

* Move to CustomBlockRegistryPopulator

* Remove name_hash from blocksTag/vanillaBlockStates

Fixes creative inventory contents with custom blocks registered

* Limit Bedrock versions to 1.19.40+

Custom blocks were released in 1.19.40

* Un-revert Crop and reorder skull textures to eliminate unused space

Should reduce memory & storage usage for Bedrock clients

Bug with top face flipping + per-face uv's was fixed in 1.19.40+
https://bugs.mojang.com/browse/MCPE-160073
Geometry is still offset by 0.5 to prevent lighting bugs

* Add validation custom block components and s/lightFilter/lightDampening/

Also validate custom block names

* Add display name component and add toggle for client block placing

The display name component allows blocks to use other locale keys.
placeAir will prevent the client from placing the default block state.

* Begin parsing block mappings (still much to do!)

* CustomBlockMapping stores block w/ all states

* Mappings almost :/

* Ok now they work at least

* Read most mapping components

* Block mappings mostly done

* Translate block item

* Add docs for custom blocks

* Add tags

* More docs

* Accidentally added name comp.

* Fix collide box and warn for >16 props

* add registerBlockItemOverride event + refactor

* Inventory overrides for multistate bedrock blocks

* Implement all remaining block components

* Minor cleanup and javadocs

* Update custom skull config example

* Address @Camotoy's review

Signed-off-by: Joshua Castle <[email protected]>

* Fix light_emission and light_dampening components

* Remove redundant populate method and remove BLOCKS_JSON after last use

* Fix inventories with block state overrides not opening

* API event for skull blocks & let register via URL

Signed-off-by: Joshua Castle <[email protected]>

* Use skin hash instead of URL

Signed-off-by: Joshua Castle <[email protected]>

* Address @davchoo's review

Signed-off-by: Joshua Castle <[email protected]>

* Rework MappingsReader_v1 to avoid passing maps around

* Treat all properties as string properties

There isn't a real need to check for boolean and int properties

* Fix block registry scan in MappingsReader

* Skin hashes can have less than 64 characters?

* Include entry when logging exceptions from block mappings

* Submodule

Signed-off-by: Joshua Castle <[email protected]>

* Fix block break speeds thanks to @Camotoy

Signed-off-by: Joshua Castle <[email protected]>

* Temporarily fix build on eclipse so I may work...

Signed-off-by: Joshua Castle <[email protected]>

* Custom tool breakspeed by server; Closes #3348

Signed-off-by: Joshua Castle <[email protected]>

* Account for if custom skulls are added on 1st run

Signed-off-by: Joshua Castle <[email protected]>

* Initial framework for extended collision boxes

Signed-off-by: Joshua Castle <[email protected]>

* Add some notes for the extended collision box impl

Signed-off-by: Joshua Castle <[email protected]>

* We have our extended collision registry

Signed-off-by: Joshua Castle <[email protected]>

* Notes for me

Signed-off-by: Joshua Castle <[email protected]>

* Extended collision boxes almost work

Signed-off-by: Joshua Castle <[email protected]>

* Extended collision boxes actually work

Signed-off-by: Joshua Castle <[email protected]>

* Consider all hitboxes in calculation

Signed-off-by: Joshua Castle <[email protected]>

* X is mirrored...

Signed-off-by: Joshua Castle <[email protected]>

* Extended collision boxes are much improved

Signed-off-by: Joshua Castle <[email protected]>

* Upstream fallout

Signed-off-by: Joshua Castle <[email protected]>

* Address @Redned235's review

Signed-off-by: Joshua Castle <[email protected]>

* Oops my bad that makes no sense :)

Signed-off-by: Joshua Castle <[email protected]>

* Ext collision box chunk translation optimization

Signed-off-by: Joshua Castle <[email protected]>

* Trunc skinhash to 32 chars due to 80 char limit

Signed-off-by: Joshua Castle <[email protected]>

* Use new transformation cmpnt vs legacy rotation

Signed-off-by: Joshua Castle <[email protected]>

* keep arr null on get extcolstor

Signed-off-by: Joshua Castle <[email protected]>

* Properly handle if extended collision box is below

Signed-off-by: Joshua Castle <[email protected]>

* Less ugly (realized it can go here)

Signed-off-by: Joshua Castle <[email protected]>

* Prevent 2x placement due to extended collision box

Signed-off-by: Joshua Castle <[email protected]>

* Properly build on eclipse via indra

Signed-off-by: Joshua Castle <[email protected]>

* Ensure enough bits in bedrockData for paletteIDs

Signed-off-by: Joshua Castle <[email protected]>

* Fix not needed whitespace

Signed-off-by: Joshua Castle <[email protected]>

* Update license headers to 2023

Signed-off-by: Joshua Castle <[email protected]>

* Use release indra over snapshot

Signed-off-by: Joshua Castle <[email protected]>

* Revert "Update license headers to 2023"

This reverts commit f750059.

* Account for collisions in chunk section y0 layer

Signed-off-by: Joshua Castle <[email protected]>

* Fix extended collision @ air section bottom

Signed-off-by: Joshua Castle <[email protected]>

* Address @davchoo's review

Signed-off-by: Joshua Castle <[email protected]>

* Address @rtm516's review

Signed-off-by: Joshua Castle <[email protected]>

* More @rtm516's review

Signed-off-by: Joshua Castle <[email protected]>

* Address @Camotoy's review

Signed-off-by: Joshua Castle <[email protected]>

* Update javadocs

Signed-off-by: Joshua Castle <[email protected]>

* Address @davchoo's review

Signed-off-by: Joshua Castle <[email protected]>

* Lock extended collision to section

Signed-off-by: Joshua Castle <[email protected]>

* Clear ext col even when air

Signed-off-by: Joshua Castle <[email protected]>

* Let override vanilla items in creative inventory

Signed-off-by: Joshua Castle <[email protected]>

* Avoid creating 12 HashSets for every overrided block state

* Super minor nitpicks + Custom Skull NBT fix

* Check custom skull is within Bedrock bounds

Fixes NPE with custom skulls above y=320 or below y=-64

* Add static builder methods to match CustomItemData API

* Upstream

Signed-off-by: Joshua Castle <[email protected]>

* Initial API setup for modded blocks (no impl yet)

Signed-off-by: Joshua Castle <[email protected]>

* More work on nonvanilla blocks (nonfunctional)

Signed-off-by: Joshua Castle <[email protected]>

* Fix compile

Signed-off-by: Joshua Castle <[email protected]>

* Update submodules

Signed-off-by: Joshua Castle <[email protected]>

* Modded reg so far (not done)

Signed-off-by: Joshua Castle <[email protected]>

* Add non-vanilla registration and fix a few bugs

* Fixes for non-vanilla blocks

* Remove import

* CustomRegPop. go1st for now; must split for modded

Signed-off-by: Joshua Castle <[email protected]>

* Address silent change to geo component for blocks

Co-Authored-By: Unoqwy <[email protected]>
Signed-off-by: Joshua Castle <[email protected]>

* Seperate bedrock, vanilla, & nonvanilla block reg

Signed-off-by: Joshua Castle <[email protected]>

* Single event

Signed-off-by: Joshua Castle <[email protected]>

* Impl MaterialInstance as builder per @Redned235

Signed-off-by: Joshua Castle <[email protected]>

* Added creative category enum & added some missing overrides (#7)

* Add material instance to provider registry

Signed-off-by: Joshua Castle <[email protected]>

* oops

Signed-off-by: Joshua Castle <[email protected]>

* Fix case of correctBedrockIdentifier not found

Signed-off-by: Joshua Castle <[email protected]>

* Fix docs

Signed-off-by: Joshua Castle <[email protected]>

* Address @Camotoy's review

Signed-off-by: Joshua Castle <[email protected]>

* Address review from @davchoo

Signed-off-by: Joshua Castle <[email protected]>

* Set namespace of custom blocks vs ident direct

Signed-off-by: Joshua Castle <[email protected]>

* Address review from @rtm516

Signed-off-by: Joshua Castle <[email protected]>

* One more

Signed-off-by: Joshua Castle <[email protected]>

* Remove rogue space

* Geo component as builder

Signed-off-by: Joshua Castle <[email protected]>

* use super name

Signed-off-by: Joshua Castle <[email protected]>

* Bump version

Signed-off-by: Joshua Castle <[email protected]>

---------

Signed-off-by: Joshua Castle <[email protected]>
Signed-off-by: GitHub <[email protected]>
Co-authored-by: davchoo <[email protected]>
Co-authored-by: davchoo <[email protected]>
Co-authored-by: Unoqwy <[email protected]>
Co-authored-by: RednedEpic <[email protected]>
Co-authored-by: ImDaBigBoss <[email protected]>
Co-authored-by: rtm516 <[email protected]>
  • Loading branch information
7 people authored Aug 21, 2023
1 parent 661a9b4 commit 9ddfdf9
Show file tree
Hide file tree
Showing 88 changed files with 6,241 additions and 334 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/

package org.geysermc.geyser.api.block.custom;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.api.GeyserApi;
import org.geysermc.geyser.api.block.custom.component.CustomBlockComponents;
import org.geysermc.geyser.api.block.custom.property.CustomBlockProperty;
import org.geysermc.geyser.api.util.CreativeCategory;

import java.util.List;
import java.util.Map;

/**
* This class is used to store data for a custom block.
*/
public interface CustomBlockData {
/**
* Gets the name of the custom block
*
* @return The name of the custom block.
*/
@NonNull String name();

/**
* Gets the identifier of the custom block
*
* @return The identifier of the custom block.
*/
@NonNull String identifier();

/**
* Gets if the custom block is included in the creative inventory
*
* @return If the custom block is included in the creative inventory.
*/
boolean includedInCreativeInventory();

/**
* Gets the item's creative category, or tab id.
*
* @return the item's creative category
*/
@Nullable CreativeCategory creativeCategory();

/**
* Gets the item's creative group.
*
* @return the item's creative group
*/
@Nullable String creativeGroup();

/**
* Gets the components of the custom block
*
* @return The components of the custom block.
*/
@Nullable CustomBlockComponents components();

/**
* Gets the custom block's map of block property names to CustomBlockProperty
* objects
*
* @return The custom block's map of block property names to CustomBlockProperty objects.
*/
@NonNull Map<String, CustomBlockProperty<?>> properties();

/**
* Gets the list of the custom block's permutations
*
* @return The permutations of the custom block.
*/
@NonNull List<CustomBlockPermutation> permutations();

/**
* Gets the custom block's default block state
*
* @return The default block state of the custom block.
*/
@NonNull CustomBlockState defaultBlockState();

/**
* Gets a builder for a custom block state
*
* @return The builder for a custom block state.
*/
CustomBlockState.@NonNull Builder blockStateBuilder();

/**
* Create a Builder for CustomBlockData
*
* @return A CustomBlockData Builder
*/
static CustomBlockData.Builder builder() {
return GeyserApi.api().provider(CustomBlockData.Builder.class);
}

interface Builder {
Builder name(@NonNull String name);

Builder includedInCreativeInventory(boolean includedInCreativeInventory);

Builder creativeCategory(@Nullable CreativeCategory creativeCategory);

Builder creativeGroup(@Nullable String creativeGroup);

Builder components(@NonNull CustomBlockComponents components);

Builder booleanProperty(@NonNull String propertyName);

Builder intProperty(@NonNull String propertyName, List<Integer> values);

Builder stringProperty(@NonNull String propertyName, List<String> values);

Builder permutations(@NonNull List<CustomBlockPermutation> permutations);

CustomBlockData build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/

package org.geysermc.geyser.api.block.custom;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.api.block.custom.component.CustomBlockComponents;

/**
* This class is used to store a custom block permutations, which contain custom
* block components mapped to a Molang query that should return true or false
*
* @param components The components of the block
* @param condition The Molang query that should return true or false
*/
public record CustomBlockPermutation(@NonNull CustomBlockComponents components, @NonNull String condition) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/

package org.geysermc.geyser.api.block.custom;

import org.checkerframework.checker.nullness.qual.NonNull;

import java.util.Map;

/**
* This class is used to store a custom block state, which contains CustomBlockData
* tied to defined properties and values
*/
public interface CustomBlockState {
/**
* Gets the custom block data associated with the state
*
* @return The custom block data for the state.
*/
@NonNull CustomBlockData block();

/**
* Gets the name of the state
*
* @return The name of the state.
*/
@NonNull String name();

/**
* Gets the given property for the state
*
* @param propertyName the property name
* @return the boolean, int, or string property.
*/
@NonNull <T> T property(@NonNull String propertyName);

/**
* Gets a map of the properties for the state
*
* @return The properties for the state.
*/
@NonNull Map<String, Object> properties();

interface Builder {
Builder booleanProperty(@NonNull String propertyName, boolean value);

Builder intProperty(@NonNull String propertyName, int value);

Builder stringProperty(@NonNull String propertyName, @NonNull String value);

CustomBlockState build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/

package org.geysermc.geyser.api.block.custom;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.api.GeyserApi;
import org.geysermc.geyser.api.block.custom.component.CustomBlockComponents;
import org.geysermc.geyser.api.util.CreativeCategory;

import java.util.List;

/**
* Represents a completely custom block that is not based on an existing vanilla Minecraft block.
*/
public interface NonVanillaCustomBlockData extends CustomBlockData {
/**
* Gets the namespace of the custom block
*
* @return The namespace of the custom block.
*/
@NonNull String namespace();


/**
* Create a Builder for NonVanillaCustomBlockData
*
* @return A NonVanillaCustomBlockData Builder
*/
static NonVanillaCustomBlockData.Builder builder() {
return GeyserApi.api().provider(NonVanillaCustomBlockData.Builder.class);
}

interface Builder extends CustomBlockData.Builder {

Builder namespace(@NonNull String namespace);

@Override
Builder name(@NonNull String name);

@Override
Builder includedInCreativeInventory(boolean includedInCreativeInventory);

@Override
Builder creativeCategory(@Nullable CreativeCategory creativeCategory);

@Override
Builder creativeGroup(@Nullable String creativeGroup);

@Override
Builder components(@NonNull CustomBlockComponents components);

@Override
Builder booleanProperty(@NonNull String propertyName);

@Override
Builder intProperty(@NonNull String propertyName, List<Integer> values);

@Override
Builder stringProperty(@NonNull String propertyName, List<String> values);

@Override
Builder permutations(@NonNull List<CustomBlockPermutation> permutations);

@Override
NonVanillaCustomBlockData build();
}
}
Loading

0 comments on commit 9ddfdf9

Please sign in to comment.