mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Added creative tabs
This commit is contained in:
parent
20cdfa4822
commit
607760e4a6
7 changed files with 54 additions and 73 deletions
|
@ -1,12 +1,18 @@
|
|||
package com.minelittlepony.unicopia.item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.minelittlepony.unicopia.USounds;
|
||||
import com.minelittlepony.unicopia.item.toxin.ToxicHolder;
|
||||
import com.minelittlepony.unicopia.item.toxin.Toxics;
|
||||
import com.minelittlepony.unicopia.item.toxin.UFoodComponents;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.Item.Settings;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.FoodComponents;
|
||||
import net.minecraft.item.MusicDiscItem;
|
||||
|
@ -17,6 +23,8 @@ import net.minecraft.util.registry.Registry;
|
|||
|
||||
public interface UItems {
|
||||
|
||||
List<Item> ITEMS = new ArrayList<>();
|
||||
|
||||
AppleItem GREEN_APPLE = register("green_apple", new AppleItem(new Item.Settings().group(ItemGroup.FOOD).food(FoodComponents.APPLE)));
|
||||
AppleItem SWEET_APPLE = register("sweet_apple", new AppleItem(new Item.Settings().group(ItemGroup.FOOD).food(FoodComponents.APPLE)));
|
||||
AppleItem SOUR_APPLE = register("sour_apple", new AppleItem(new Item.Settings().group(ItemGroup.FOOD).food(FoodComponents.APPLE)));
|
||||
|
@ -32,6 +40,7 @@ public interface UItems {
|
|||
Item MUSIC_DISC_FUNK = register("music_disc_funk", USounds.RECORD_FUNK);
|
||||
|
||||
static <T extends Item> T register(String name, T item) {
|
||||
ITEMS.add(item);
|
||||
if (item instanceof BlockItem) {
|
||||
((BlockItem)item).appendBlocks(Item.BLOCK_ITEMS, item);
|
||||
}
|
||||
|
@ -48,5 +57,17 @@ public interface UItems {
|
|||
|
||||
static void bootstrap() {
|
||||
Toxics.bootstrap();
|
||||
|
||||
FabricItemGroupBuilder.create(new Identifier("unicopia", "items")).appendItems(list -> {
|
||||
list.addAll(VanillaOverrides.REGISTRY.stream().map(Item::getStackForRender).collect(Collectors.toList()));
|
||||
list.addAll(ITEMS.stream().map(Item::getStackForRender).collect(Collectors.toList()));
|
||||
}).icon(ZAP_APPLE::getStackForRender).build();
|
||||
|
||||
FabricItemGroupBuilder.create(new Identifier("unicopia", "horsefeed")).appendItems(list -> {
|
||||
list.addAll(Registry.ITEM.stream()
|
||||
.filter(item -> item instanceof ToxicHolder && ((ToxicHolder)item).getToxic().isPresent())
|
||||
.map(Item::getStackForRender)
|
||||
.collect(Collectors.toList()));
|
||||
}).icon(ZAP_APPLE::getStackForRender).build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,4 +19,4 @@ public final class VanillaOverrides {
|
|||
static {
|
||||
register("apple", new AppleItem(new Item.Settings().group(ItemGroup.FOOD).food(FoodComponents.APPLE)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import com.minelittlepony.unicopia.entity.player.Pony;
|
|||
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.ActionResult;
|
||||
|
@ -19,18 +18,15 @@ import net.minecraft.world.World;
|
|||
|
||||
public class Toxic {
|
||||
|
||||
private final Item item;
|
||||
|
||||
private final UseAction action;
|
||||
private final Function<ItemStack, Toxicity> toxicity;
|
||||
private final Toxin toxin;
|
||||
|
||||
Toxic(Item item, UseAction action, Toxin toxin, Toxicity toxicity) {
|
||||
this(item, action, toxin, stack -> toxicity);
|
||||
Toxic(UseAction action, Toxin toxin, Toxicity toxicity) {
|
||||
this(action, toxin, stack -> toxicity);
|
||||
}
|
||||
|
||||
Toxic(Item item, UseAction action, Toxin toxin, Function<ItemStack, Toxicity> toxicity) {
|
||||
this.item = item;
|
||||
Toxic(UseAction action, Toxin toxin, Function<ItemStack, Toxicity> toxicity) {
|
||||
this.action = action;
|
||||
this.toxin = toxin;
|
||||
this.toxicity = toxicity;
|
||||
|
@ -52,7 +48,11 @@ public class Toxic {
|
|||
toxin.afflict((PlayerEntity)entity, t, stack);
|
||||
}
|
||||
|
||||
return new ItemStack(item.getRecipeRemainder());
|
||||
if (!(entity instanceof PlayerEntity) || !((PlayerEntity)entity).abilities.creativeMode) {
|
||||
stack.decrement(1);
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand, Supplier<TypedActionResult<ItemStack>> sup) {
|
||||
|
|
|
@ -1,8 +1,15 @@
|
|||
package com.minelittlepony.unicopia.item.toxin;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import net.minecraft.item.FoodComponent;
|
||||
|
||||
public interface ToxicHolder {
|
||||
void setFood(FoodComponent food);
|
||||
|
||||
void setToxic(Toxic toxic);
|
||||
|
||||
default Optional<Toxic> getToxic() {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
package com.minelittlepony.unicopia.item.toxin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.item.TooltipContext;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.UseAction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ToxicItem extends Item {
|
||||
|
||||
private final Toxic toxic;
|
||||
|
||||
public ToxicItem(Item.Settings settings, UseAction action, Toxicity toxicity, Toxin toxin) {
|
||||
this(settings, action, stack -> toxicity, toxin);
|
||||
}
|
||||
|
||||
public ToxicItem(Item.Settings settings, UseAction action, Function<ItemStack, Toxicity> toxicity, Toxin toxin) {
|
||||
super(settings);
|
||||
this.toxic = new Toxic(this, action, toxin, toxicity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UseAction getUseAction(ItemStack stack) {
|
||||
return toxic.getUseAction(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
|
||||
tooltip.add(toxic.getTooltip(stack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack finishUsing(ItemStack stack, World world, LivingEntity entity) {
|
||||
super.finishUsing(stack, world, entity);
|
||||
return toxic.finishUsing(stack, world, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
||||
return toxic.use(world, player, hand, () -> super.use(world, player, hand));
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@ public interface Toxics {
|
|||
static void bootstrap() {}
|
||||
|
||||
static Toxic register(Item target, FoodComponent food, UseAction action, Toxicity toxicity, Toxin toxin) {
|
||||
Toxic toxic = new Toxic(target, action, toxin, toxicity);
|
||||
Toxic toxic = new Toxic(action, toxin, toxicity);
|
||||
ToxicHolder holder = (ToxicHolder)target;
|
||||
holder.setFood(food);
|
||||
holder.setToxic(toxic);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.minelittlepony.unicopia.mixin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -28,43 +29,47 @@ import net.minecraft.world.World;
|
|||
abstract class MixinBlockItem extends Item implements ToxicHolder {
|
||||
public MixinBlockItem() {super(null); }
|
||||
|
||||
@Nullable
|
||||
private Toxic toxic;
|
||||
private Optional<Toxic> toxic = Optional.empty();
|
||||
|
||||
@Override
|
||||
public void setToxic(Toxic toxic) {
|
||||
this.toxic = toxic;
|
||||
this.toxic = Optional.of(toxic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Toxic> getToxic() {
|
||||
return toxic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UseAction getUseAction(ItemStack stack) {
|
||||
if (toxic != null) {
|
||||
return toxic.getUseAction(stack);
|
||||
if (toxic.isPresent()) {
|
||||
return toxic.get().getUseAction(stack);
|
||||
}
|
||||
return super.getUseAction(stack);
|
||||
}
|
||||
|
||||
@Inject(method = "appendTooltip", at = @At("RETURN"))
|
||||
private void onAppendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context, CallbackInfo into) {
|
||||
if (toxic != null) {
|
||||
tooltip.add(toxic.getTooltip(stack));
|
||||
if (toxic.isPresent()) {
|
||||
tooltip.add(toxic.get().getTooltip(stack));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack finishUsing(ItemStack stack, World world, LivingEntity entity) {
|
||||
ItemStack result = super.finishUsing(stack, world, entity);
|
||||
if (toxic != null) {
|
||||
return toxic.finishUsing(stack, world, entity);
|
||||
if (toxic.isPresent()) {
|
||||
return toxic.get().finishUsing(stack, world, entity);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
||||
if (toxic == null) {
|
||||
if (!toxic.isPresent()) {
|
||||
return super.use(world, player, hand);
|
||||
}
|
||||
return toxic.use(world, player, hand, () -> super.use(world, player, hand));
|
||||
return toxic.get().use(world, player, hand, () -> super.use(world, player, hand));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue