Skip to content

Commit

Permalink
changes requested by reviewer
Browse files Browse the repository at this point in the history
  • Loading branch information
OmeWillem committed Nov 12, 2024
1 parent 62d9dea commit 9efb855
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ default boolean isTool() {
return displayHandheld();
}

/**
* @deprecated Use {@link #blockPlacer()} instead.
* Gets the block the item places.
*
* @return the block the item places
*/
String block();

/**
* Gets the block placer settings, if it's null then the component won't be added.
*
Expand Down Expand Up @@ -208,6 +216,12 @@ interface Builder extends CustomItemData.Builder {

Builder chargeable(boolean isChargeable);

/**
* @deprecated Use {@link #blockPlacer(CustomBlockPlacer)} instead.
*/
@Deprecated
Builder block(String block);

Builder blockPlacer(CustomBlockPlacer blockPlacer);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ public boolean isChargeable() {
return isChargeable;
}

@Override
public String block() {
return blockPlacer == null ? null : blockPlacer.block();
}

@Override
public CustomBlockPlacer blockPlacer() {
return blockPlacer;
Expand Down Expand Up @@ -348,6 +353,12 @@ public Builder chargeable(boolean isChargeable) {
return this;
}

@Override
public Builder block(String block) {
this.blockPlacer = new CustomBlockPlacer(block, false);
return this;
}

@Override
public Builder blockPlacer(CustomBlockPlacer blockPlacer) {
this.blockPlacer = blockPlacer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,7 @@
import org.geysermc.geyser.registry.type.ItemMapping;
import org.geysermc.geyser.registry.type.NonVanillaItemRegistration;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.*;

public class CustomItemRegistryPopulator {
public static void populate(Map<String, GeyserMappingItem> items, Multimap<String, CustomItemData> customItems, List<NonVanillaCustomItemData> nonVanillaCustomItems) {
Expand Down Expand Up @@ -173,7 +168,7 @@ private static NbtMapBuilder createComponentNbt(CustomItemData customItemData, I
NbtMapBuilder itemProperties = NbtMap.builder();
NbtMapBuilder componentBuilder = NbtMap.builder();

setupBasicItemInfo(javaItem.maxDamage(), javaItem.maxStackSize(), mapping.getToolType() != null || customItemData.displayHandheld(), customItemData, itemProperties, componentBuilder, protocolVersion);
setupBasicItemInfo(javaItem.maxDamage(), javaItem.maxStackSize(), mapping.getToolType() != null || customItemData.displayHandheld(), false, customItemData, itemProperties, componentBuilder, protocolVersion);

boolean canDestroyInCreative = true;
if (mapping.getToolType() != null) { // This is not using the isTool boolean because it is not just a render type here.
Expand Down Expand Up @@ -201,7 +196,8 @@ private static NbtMapBuilder createComponentNbt(CustomItemData customItemData, I
case "minecraft:fire_charge", "minecraft:flint_and_steel" -> computeBlockItemProperties(new CustomBlockPlacer("minecraft:fire", false), componentBuilder);
case "minecraft:bow", "minecraft:crossbow", "minecraft:trident" -> computeChargeableProperties(itemProperties, componentBuilder, mapping.getBedrockIdentifier(), protocolVersion);
case "minecraft:honey_bottle", "minecraft:milk_bucket", "minecraft:potion" -> computeConsumableProperties(itemProperties, componentBuilder, 2, true);
case "minecraft:experience_bottle", "minecraft:egg", "minecraft:ender_pearl", "minecraft:ender_eye", "minecraft:lingering_potion", "minecraft:snowball", "minecraft:splash_potion" -> computeThrowableProperties(componentBuilder);
case "minecraft:experience_bottle", "minecraft:egg", "minecraft:ender_pearl", "minecraft:ender_eye", "minecraft:lingering_potion", "minecraft:snowball", "minecraft:splash_potion" ->
computeThrowableProperties(componentBuilder);
}

// Hardcoded on Java, and should extend to the custom item
Expand All @@ -227,7 +223,10 @@ private static NbtMapBuilder createComponentNbt(NonVanillaCustomItemData customI
NbtMapBuilder itemProperties = NbtMap.builder();
NbtMapBuilder componentBuilder = NbtMap.builder();

setupBasicItemInfo(customItemData.maxDamage(), customItemData.stackSize(), displayHandheld, customItemData, itemProperties, componentBuilder, protocolVersion);
// this can replace minecraft:icon, so we have to add this here.
boolean replaceBlockItem = customItemData.blockPlacer() != null && customItemData.blockPlacer().replaceBlockItem();

setupBasicItemInfo(customItemData.maxDamage(), customItemData.stackSize(), displayHandheld, replaceBlockItem, customItemData, itemProperties, componentBuilder, protocolVersion);

boolean canDestroyInCreative = true;
if (customItemData.toolType() != null) { // This is not using the isTool boolean because it is not just a render type here.
Expand Down Expand Up @@ -269,13 +268,15 @@ private static NbtMapBuilder createComponentNbt(NonVanillaCustomItemData customI
return builder;
}

private static void setupBasicItemInfo(int maxDamage, int stackSize, boolean displayHandheld, CustomItemData customItemData, NbtMapBuilder itemProperties, NbtMapBuilder componentBuilder, int protocolVersion) {
NbtMap iconMap = NbtMap.builder()
.putCompound("textures", NbtMap.builder()
.putString("default", customItemData.icon())
.build())
.build();
itemProperties.putCompound("minecraft:icon", iconMap);
private static void setupBasicItemInfo(int maxDamage, int stackSize, boolean displayHandheld, boolean replaceBlockItem, CustomItemData customItemData, NbtMapBuilder itemProperties, NbtMapBuilder componentBuilder, int protocolVersion) {
if (!replaceBlockItem) {
NbtMap iconMap = NbtMap.builder()
.putCompound("textures", NbtMap.builder()
.putString("default", customItemData.icon())
.build())
.build();
itemProperties.putCompound("minecraft:icon", iconMap);
}

if (customItemData.creativeCategory().isPresent()) {
itemProperties.putInt("creative_category", customItemData.creativeCategory().getAsInt());
Expand Down Expand Up @@ -499,7 +500,7 @@ private static void computeConsumableProperties(NbtMapBuilder itemProperties, Nb

private static void computeEntityPlacerProperties(NbtMapBuilder componentBuilder) {
// all items registered that place entities should be given this component to prevent double placement
// it is okay that the entity here does not match the actual one since we control what entity actually spawns
// it is okay that the entity here does not match the actual one since we control what entity actually spawns
componentBuilder.putCompound("minecraft:entity_placer", NbtMap.builder().putString("entity", "minecraft:minecart").build());
}

Expand Down

0 comments on commit 9efb855

Please sign in to comment.