Skip to content

Commit

Permalink
修改了一部分ItemReg和ItemProperties,修正了Crafting Remainder注册会导致游戏无法正常启动的问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
MegumiKasuga committed Oct 3, 2024
1 parent 04e434d commit cdd9dc6
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package kasuga.lib.core.base.item_helper;

import net.minecraft.world.item.Item;

import javax.annotation.Nonnull;
import java.util.function.Supplier;

public class ExternalProperties extends Item.Properties {

@Nonnull
Supplier<Item> craftingRemainderItem = () -> null;

public ExternalProperties craftRemainder(Supplier<Item> craftingReminderItem) {
this.craftingRemainderItem = craftingReminderItem;
return this;
}

/**
* Don't use, use {@link ExternalProperties#craftRemainder(Supplier)} instead.
* @param pCraftingRemainingItem Don't use.
* @return self.
*/
@Deprecated
@Override
public Item.Properties craftRemainder(Item pCraftingRemainingItem) {
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package kasuga.lib.core.base.item_helper;

import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;

import javax.annotation.Nonnull;
import java.util.function.Supplier;

public class ExternalRemainderBlockItem extends BlockItem {

@Nonnull
private final Supplier<Item> craftingRemainder;
public ExternalRemainderBlockItem(Block pBlock, Properties pProperties) {
super(pBlock, pProperties);
if (pProperties instanceof ExternalProperties externalProperties)
craftingRemainder = externalProperties.craftingRemainderItem;
else
craftingRemainder = () -> null;
}

@Nonnull
public Supplier<Item> getCraftingRemainder() {
return craftingRemainder;
}

@Override
public boolean hasCraftingRemainingItem(ItemStack stack) {
return super.hasCraftingRemainingItem(stack) || craftingRemainder.get() != null;
}

@Override
public ItemStack getCraftingRemainingItem(ItemStack itemStack) {
ItemStack remain = super.getCraftingRemainingItem(itemStack);
if (remain == ItemStack.EMPTY && craftingRemainder.get() != null) {
remain = craftingRemainder.get().getDefaultInstance();
}
return remain;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package kasuga.lib.core.base.item_helper;

import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;

import javax.annotation.Nonnull;
import java.util.function.Supplier;

public class ExternalRemainderItem extends Item {

@Nonnull
private final Supplier<Item> craftingRemainder;
public ExternalRemainderItem(Properties pProperties) {
super(pProperties);
if (pProperties instanceof ExternalProperties externalProperties)
craftingRemainder = externalProperties.craftingRemainderItem;
else
craftingRemainder = () -> null;
}

@Nonnull
public Supplier<Item> getCraftingRemainder() {
return craftingRemainder;
}

@Override
public boolean hasCraftingRemainingItem(ItemStack stack) {
return super.hasCraftingRemainingItem(stack) || craftingRemainder.get() != null;
}

@Override
public ItemStack getCraftingRemainingItem(ItemStack itemStack) {
ItemStack remain = super.getCraftingRemainingItem(itemStack);
if (remain == ItemStack.EMPTY && craftingRemainder.get() != null) {
remain = craftingRemainder.get().getDefaultInstance();
}
return remain;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kasuga.lib.registrations.common;

import kasuga.lib.core.annos.Mandatory;
import kasuga.lib.core.base.item_helper.ExternalProperties;
import kasuga.lib.registrations.Reg;
import kasuga.lib.registrations.registry.SimpleRegistry;
import net.minecraft.client.gui.screens.MenuScreens;
Expand Down Expand Up @@ -33,7 +34,7 @@ public class BucketItemReg<T extends BucketItem> extends ItemReg<T> {
private boolean customRender = false;
private BucketBuilder<T> builder;

public final Item.Properties properties = new Item.Properties();
public final Item.Properties properties = new ExternalProperties();
private RegistryObject<T> registryObject = null;
private MenuReg<?, ?> menuReg = null;
private Supplier<? extends ForgeFlowingFluid> fluid = null;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/kasuga/lib/registrations/common/ItemReg.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import kasuga.lib.core.annos.Mandatory;
import kasuga.lib.core.annos.Optional;
import kasuga.lib.core.base.item_helper.ExternalProperties;
import kasuga.lib.registrations.Reg;
import kasuga.lib.registrations.registry.SimpleRegistry;
import net.minecraft.client.gui.screens.MenuScreens;
Expand Down Expand Up @@ -30,7 +31,7 @@ public class ItemReg<T extends Item> extends Reg {
private boolean customRender = false;
private ItemBuilder<T> builder;

public final Item.Properties properties = new Item.Properties();
public final Item.Properties properties = new ExternalProperties();
private RegistryObject<T> registryObject = null;
private MenuReg<?, ?> menuReg = null;
private final List<TagKey<?>> tags;
Expand Down

0 comments on commit cdd9dc6

Please sign in to comment.