Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brnbrd committed Jul 22, 2024
1 parent 584dd30 commit 865f36d
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 26 deletions.
6 changes: 5 additions & 1 deletion src/main/java/net/brnbrd/delightful/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ public static ObjectArrayList<ItemStack> with(ObjectArrayList<ItemStack> before,
return ForgeRegistries.BLOCKS.getValue(rl);
}

public static ItemStack gs(RegistryObject<Item> r, int count) {
return new ItemStack(r.get(), count);
}

public static ItemStack gs(RegistryObject<Item> r) {
return r.get().getDefaultInstance();
return gs(r, 1);
}

public static String name(Item item) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.brnbrd.delightful.common.block;

import net.brnbrd.delightful.Util;
import net.brnbrd.delightful.common.item.DelightfulItems;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -48,9 +49,7 @@ public CantaloupePlantBlock(BlockBehaviour.Properties pProperties) {

@Override
public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGetter level, BlockPos pos, Player player) {
return this.isMaxAge(state) ?
DelightfulItems.CANTALOUPE.get().getDefaultInstance() :
DelightfulItems.CANTALOUPE_SEEDS.get().getDefaultInstance();
return Util.gs(this.isMaxAge(state) ? DelightfulItems.CANTALOUPE : DelightfulItems.CANTALOUPE_SEEDS);
}

@Override
Expand Down Expand Up @@ -119,7 +118,7 @@ public boolean canSurvive(@NotNull BlockState pState, LevelReader pLevel, BlockP
if (!flag && pPlayer.getItemInHand(pHand).is(Items.BONE_MEAL)) {
return InteractionResult.PASS;
} else if (flag) {
popResource(pLevel, pPos, new ItemStack(DelightfulItems.CANTALOUPE.get(), 1));
popResource(pLevel, pPos, Util.gs(DelightfulItems.CANTALOUPE));
pLevel.playSound(null, pPos, SoundEvents.SWEET_BERRY_BUSH_PICK_BERRIES, SoundSource.BLOCKS, 1.0F, 0.8F + pLevel.random.nextFloat() * 0.4F);
BlockState blockstate = state.setValue(AGE, 0);
pLevel.setBlock(pPos, blockstate, 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public DPieBlock(Supplier<Item> pieSlice, ResourceLocation pie) {

public @NotNull ItemStack getStack() {
if (ForgeRegistries.ITEMS.containsKey(this.pie)) {
return this.asItem().getDefaultInstance();
return new ItemStack(this.asItem());
}
return ItemStack.EMPTY;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.brnbrd.delightful.common.block;

import net.brnbrd.delightful.Util;
import net.brnbrd.delightful.common.item.DelightfulItems;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
Expand Down Expand Up @@ -45,7 +46,7 @@ public SalmonberryBushBlock(BlockBehaviour.Properties pProperties) {

@Override
public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGetter level, BlockPos pos, Player player) {
return state.getValue(AGE) <= 2 ? DelightfulItems.SALMONBERRY_PIPS.get().getDefaultInstance() : DelightfulItems.SALMONBERRIES.get().getDefaultInstance();
return state.getValue(AGE) <= 2 ? Util.gs(DelightfulItems.SALMONBERRY_PIPS) : DelightfulItems.SALMONBERRIES.get().getDefaultInstance();
}

@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -99,7 +100,7 @@ public void randomTick(BlockState pState, @NotNull ServerLevel pLevel, @NotNull
if (!flag && player.getItemInHand(hand).is(Items.BONE_MEAL)) {
return InteractionResult.PASS;
} else if (state.getValue(AGE) > 2) {
popResource(level, pos, new ItemStack(DelightfulItems.SALMONBERRIES.get(), (flag ? 2 + level.random.nextInt(2) : 1)));
popResource(level, pos, Util.gs(DelightfulItems.SALMONBERRIES, (flag ? 2 + level.random.nextInt(2) : 1)));
level.playSound(null, pos, SoundEvents.SWEET_BERRY_BUSH_PICK_BERRIES, SoundSource.BLOCKS, 1.0F, 0.8F + level.random.nextFloat() * 0.4F);
BlockState blockstate = state.setValue(AGE, 1);
level.setBlock(pos, blockstate, 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public ItemStack getSliceItem() {
}

public ItemStack getJuiceItem() {
return this.juiceItem.get().getDefaultInstance();
return new ItemStack(this.juiceItem.get());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ public IntegerProperty getBitesProperty() {

@Override
public ItemStack getSliceItem() {
return this.sliceItem.get().getDefaultInstance();
return new ItemStack(this.sliceItem.get());
}

@Nullable
public ItemStack getJuiceItem() {
return this.juiceItem.get().getDefaultInstance();
return new ItemStack(this.juiceItem.get());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void onWanderingTrader(WandererTradesEvent e) {
trades.add((ent, r) -> new MerchantOffer(new ItemStack(Items.EMERALD, 1), Util.gs(DelightfulItems.SALMONBERRY_PIPS), 5, 1, 1));
}
if (Util.enabled(DelightfulItems.CANTALOUPE) && Util.enabled(DelightfulItems.CANTALOUPE_SLICE)) {
trades.add((ent, r) -> new MerchantOffer(new ItemStack(Items.EMERALD, 2), new ItemStack(DelightfulItems.CANTALOUPE_SLICE.get(), 8), 5, 1, 1));
trades.add((ent, r) -> new MerchantOffer(new ItemStack(Items.EMERALD, 2), Util.gs(DelightfulItems.CANTALOUPE_SLICE, 8), 5, 1, 1));
}
}

Expand All @@ -62,10 +62,13 @@ void onInteract(PlayerInteractEvent.RightClickBlock e) {
) {
SlicedGourdBlock sliced = (SlicedGourdBlock) DelightfulBlocks.SLICED_GLOOMGOURD.get();
slice(sliced.defaultBlockState(), sliced.getSliceItem(), world, pos, SoundEvents.BAMBOO_BREAK, e, client);
} else if (Mods.loaded(Mods.FU, Mods.FUD) &&
Util.name(current.getBlock()).equals("truffle_cake")) {
} else if (
Mods.loaded(Mods.FU, Mods.FUD) &&
Util.name(current.getBlock()).equals("truffle_cake") &&
ForgeRegistries.ITEMS.containsKey(Util.rl(Mods.FUD, "truffle_cake_slice"))
) {
int currentBites = current.getValue(BlockStateProperties.BITES);
ItemStack slice = Objects.requireNonNull(Util.item(Mods.FUD, "truffle_cake_slice")).getDefaultInstance();
ItemStack slice = new ItemStack(Objects.requireNonNull(Util.item(Mods.FUD, "truffle_cake_slice")));
if (currentBites >= 3) {
world.removeBlock(pos, false);
world.gameEvent(e.getEntity(), GameEvent.BLOCK_DESTROY, pos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.brnbrd.delightful.common.crafting.EnabledCondition;
import net.brnbrd.delightful.common.item.DelightfulItems;
import net.brnbrd.delightful.common.item.IConfigured;
import net.brnbrd.delightful.common.item.knife.DelightfulKnifeItem;
import net.brnbrd.delightful.compat.Mods;
import net.brnbrd.delightful.data.tags.DelightfulItemTags;
import net.brnbrd.delightful.network.DPacketHandler;
Expand Down Expand Up @@ -112,7 +113,8 @@ public void buildContents(BuildCreativeModeTabContentsEvent event) {
if (event.getTabKey() == ModCreativeTabs.TAB_FARMERS_DELIGHT.getKey()) {
DelightfulItems.ITEMS.getEntries().stream().filter(RegistryObject::isPresent).forEach((item) -> {
Item i = item.get();
ItemStack inst = i.getDefaultInstance();
ItemStack inst = i instanceof DelightfulKnifeItem ?
((DelightfulKnifeItem) i).getCreativeItem() : new ItemStack(i);
if (
(i instanceof IConfigured conf && conf.enabled() && !inst.isEmpty()) ||
!(i instanceof IConfigured))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
import net.minecraftforge.registries.tags.ITagManager;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.codehaus.plexus.util.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import vectorwing.farmersdelight.common.item.KnifeItem;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class DelightfulKnifeItem extends KnifeItem implements IConfigured {
private final TagKey<Item> tag;
Expand Down Expand Up @@ -79,6 +79,10 @@ public Ingredient getRod() {
return Ingredient.of(Tags.Items.RODS_WOODEN);
}

public @NotNull ItemStack getCreativeItem() {
return new ItemStack(this);
}

public ImmutablePair<Ingredient, Ingredient> getSmithing() {
return ImmutablePair.nullPair();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public String[] getConflicts() {
}

@Override
public @NotNull ItemStack getDefaultInstance() {
return Util.enchant(super.getDefaultInstance(), ModEnchantments.BACKSTABBING.get(), 1);
public @NotNull ItemStack getCreativeItem() {
return Util.enchant(super.getCreativeItem(), ModEnchantments.BACKSTABBING.get(), 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public String[] getConflicts() {
}

@Override
public @NotNull ItemStack getDefaultInstance() {
return Util.enchant(super.getDefaultInstance(), Enchantments.SMITE, 2);
public @NotNull ItemStack getCreativeItem() {
return Util.enchant(super.getCreativeItem(), Enchantments.SMITE, 2);
}
}
8 changes: 4 additions & 4 deletions src/main/java/net/brnbrd/delightful/compat/JEIPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ public void registerRecipes(IRecipeRegistration registration) {
);
}
if (((GreenTeaLeavesItem)DelightfulItems.GREEN_TEA_LEAF.get()).enabled()) {
registration.addIngredientInfo(DelightfulItems.GREEN_TEA_LEAF.get().getDefaultInstance(), VanillaTypes.ITEM_STACK, Component.translatable(Delightful.MODID + ".green_tea_leaf.desc"));
registration.addIngredientInfo(Util.gs(DelightfulItems.GREEN_TEA_LEAF), VanillaTypes.ITEM_STACK, Component.translatable(Delightful.MODID + ".green_tea_leaf.desc"));
}
if (Util.enabled(DelightfulItems.ACORN)) {
registration.addIngredientInfo(Util.gs(DelightfulItems.ACORN), VanillaTypes.ITEM_STACK, Component.translatable(Delightful.MODID + ".acorn.desc"));
}
if (Util.enabled(DelightfulItems.MINI_MELON)) {
registration.addIngredientInfo(
List.of(Items.MELON_SLICE.getDefaultInstance(), Util.gs(DelightfulItems.MINI_MELON)),
List.of(new ItemStack(Items.MELON_SLICE), Util.gs(DelightfulItems.MINI_MELON)),
VanillaTypes.ITEM_STACK, Component.translatable(Delightful.MODID + ".mini_melon.desc"));
}
if (Util.enabled(DelightfulItems.CANTALOUPE)) {
Expand All @@ -102,8 +102,8 @@ public void registerRecipes(IRecipeRegistration registration) {
if (Util.enabled(DelightfulItems.ANIMAL_OIL_BOTTLE)) {
registration.addIngredientInfo(Util.gs(DelightfulItems.ANIMAL_OIL_BOTTLE), VanillaTypes.ITEM_STACK, Component.translatable(Delightful.MODID + ".animal_oil_bottle.desc"));
}
registration.addIngredientInfo(Items.MELON.getDefaultInstance(), VanillaTypes.ITEM_STACK, Component.translatable(Delightful.MODID + ".sliceable.desc"));
registration.addIngredientInfo(Items.PUMPKIN.getDefaultInstance(), VanillaTypes.ITEM_STACK, Component.translatable(Delightful.MODID + ".sliceable.desc"));
registration.addIngredientInfo(new ItemStack(Items.MELON), VanillaTypes.ITEM_STACK, Component.translatable(Delightful.MODID + ".sliceable.desc"));
registration.addIngredientInfo(new ItemStack(Items.PUMPKIN), VanillaTypes.ITEM_STACK, Component.translatable(Delightful.MODID + ".sliceable.desc"));
}

private void hide(List<ItemStack> hiddenList, String modid, String item, String... conflicts) {
Expand Down

0 comments on commit 865f36d

Please sign in to comment.