mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-01 19:46:42 +01:00
Rewrite toxins and get rid of a lot of item replacements and other fixes
This commit is contained in:
parent
55a559321a
commit
d95086c807
16 changed files with 217 additions and 175 deletions
|
@ -1,5 +1,8 @@
|
|||
package com.minelittlepony.unicopia.ability;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
|
@ -7,7 +10,7 @@ import net.minecraft.util.registry.MutableRegistry;
|
|||
import net.minecraft.util.registry.SimpleRegistry;
|
||||
|
||||
public interface Abilities {
|
||||
MutableRegistry<Integer> KEYS_CODES = new SimpleRegistry<>();
|
||||
Map<Identifier, Integer> KEYS_CODES = new HashMap<>();
|
||||
MutableRegistry<Ability<?>> REGISTRY = new SimpleRegistry<>();
|
||||
|
||||
// unicorn / alicorn
|
||||
|
@ -32,7 +35,7 @@ public interface Abilities {
|
|||
|
||||
static <T extends Ability<?>> T register(T power, String name, int keyCode) {
|
||||
Identifier id = new Identifier("unicopia", name);
|
||||
KEYS_CODES.add(id, keyCode);
|
||||
KEYS_CODES.put(id, keyCode);
|
||||
return REGISTRY.add(id, power);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,13 +14,12 @@ import net.minecraft.util.Hand;
|
|||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.BlockPointer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Position;
|
||||
import net.minecraft.world.RayTraceContext;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class CloudPlacerItem extends Item implements Dispensable {
|
||||
public class CloudPlacerItem extends Item {
|
||||
|
||||
private final EntityType<? extends CloudEntity> cloudSupplier;
|
||||
|
||||
|
@ -31,7 +30,15 @@ public class CloudPlacerItem extends Item implements Dispensable {
|
|||
);
|
||||
this.cloudSupplier = spawner;
|
||||
|
||||
setDispenseable();
|
||||
Dispensable.setDispenseable(this, (source, stack) -> {
|
||||
Position pos = DispenserBlock.getOutputLocation(source);
|
||||
|
||||
placeCloud(source.getWorld(), new BlockPos(pos.getX(), pos.getY(), pos.getZ()));
|
||||
|
||||
stack.decrement(1);
|
||||
|
||||
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
|
||||
});
|
||||
}
|
||||
|
||||
public void placeCloud(World world, BlockPos pos) {
|
||||
|
@ -66,15 +73,4 @@ public class CloudPlacerItem extends Item implements Dispensable {
|
|||
|
||||
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedActionResult<ItemStack> dispenseStack(BlockPointer source, ItemStack stack) {
|
||||
Position pos = DispenserBlock.getOutputLocation(source);
|
||||
|
||||
placeCloud(source.getWorld(), new BlockPos(pos.getX(), pos.getY(), pos.getZ()));
|
||||
|
||||
stack.decrement(1);
|
||||
|
||||
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,25 +16,17 @@ import net.minecraft.item.Items;
|
|||
import net.minecraft.item.ShearsItem;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.math.BlockPointer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ExtendedShearsItem extends ShearsItem implements Dispensable {
|
||||
|
||||
private final Optional<DispenserBehavior> vanillaDispenserBehaviour = getBehavior(new ItemStack(Items.SHEARS));
|
||||
public class ExtendedShearsItem extends ShearsItem {
|
||||
|
||||
public ExtendedShearsItem() {
|
||||
super(new Item.Settings().maxDamage(238).group(ItemGroup.TOOLS));
|
||||
setDispenseable();
|
||||
DispenserBlock.registerBehavior(Items.SHEARS, getBehavior(new ItemStack(this)).get());
|
||||
}
|
||||
final Optional<DispenserBehavior> vanillaDispenserBehaviour = Dispensable.getBehavior(new ItemStack(Items.SHEARS));
|
||||
DispenserBlock.registerBehavior(Items.SHEARS, Dispensable.setDispenseable(this, (source, stack) -> {
|
||||
|
||||
@Override
|
||||
public TypedActionResult<ItemStack> dispenseStack(BlockPointer source, ItemStack stack) {
|
||||
Direction facing = source.getBlockState().get(DispenserBlock.FACING);
|
||||
BlockPos pos = source.getBlockPos().offset(facing);
|
||||
BlockPos pos = source.getBlockPos().offset(source.getBlockState().get(DispenserBlock.FACING));
|
||||
World w = source.getWorld();
|
||||
|
||||
if (UItems.MOSS.tryConvert(w, w.getBlockState(pos), pos, null)) {
|
||||
|
@ -44,8 +36,11 @@ public class ExtendedShearsItem extends ShearsItem implements Dispensable {
|
|||
}
|
||||
|
||||
return vanillaDispenserBehaviour
|
||||
.map(action -> TypedActionResult.success(action.dispense(source, stack)))
|
||||
.map(action -> {
|
||||
return TypedActionResult.pass(action.dispense(source, stack));
|
||||
})
|
||||
.orElseGet(() -> TypedActionResult.fail(stack));
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.minelittlepony.unicopia.magic.Affinity;
|
|||
import com.minelittlepony.unicopia.magic.CastResult;
|
||||
import com.minelittlepony.unicopia.magic.Castable;
|
||||
import com.minelittlepony.unicopia.magic.DispenceableMagicEffect;
|
||||
import com.minelittlepony.unicopia.magic.Dispensable;
|
||||
import com.minelittlepony.unicopia.magic.MagicEffect;
|
||||
import com.minelittlepony.unicopia.magic.Useable;
|
||||
import com.minelittlepony.unicopia.magic.spell.SpellRegistry;
|
||||
|
@ -40,8 +41,7 @@ public class MagicGemItem extends Item implements Castable {
|
|||
super(new Settings()
|
||||
.maxCount(16)
|
||||
.group(ItemGroup.BREWING));
|
||||
|
||||
setDispenseable();
|
||||
Dispensable.setDispenseable(this, this::dispenseStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -30,14 +30,9 @@ public class MossItem extends ToxicItem {
|
|||
|
||||
if (!state.equals(converted)) {
|
||||
world.setBlockState(pos, converted, 3);
|
||||
|
||||
world.playSound(null, pos, SoundEvents.ENTITY_SHEEP_SHEAR, SoundCategory.PLAYERS, 1, 1);
|
||||
|
||||
int amount = 1;
|
||||
|
||||
if (player != null && Pony.of(player).getSpecies().canUseEarth()) {
|
||||
amount = world.random.nextInt(4);
|
||||
}
|
||||
int amount = player != null && Pony.of(player).getSpecies().canUseEarth() ? world.random.nextInt(4) : 1;
|
||||
|
||||
Block.dropStack(world, pos, new ItemStack(this, amount));
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.item;
|
|||
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import com.minelittlepony.unicopia.magic.Caster;
|
||||
import com.minelittlepony.unicopia.magic.Dispensable;
|
||||
import com.minelittlepony.unicopia.util.projectile.TossableItem;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
|
@ -21,7 +22,7 @@ public class RottenTomatoItem extends TomatoItem implements TossableItem {
|
|||
|
||||
public RottenTomatoItem(Settings settings) {
|
||||
super(settings);
|
||||
setDispenseable();
|
||||
Dispensable.setDispenseable(this, this::dispenseStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,23 +12,29 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||
import net.minecraft.item.BookItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.math.BlockPointer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class SpellbookItem extends BookItem implements Dispensable {
|
||||
public class SpellbookItem extends BookItem {
|
||||
|
||||
public SpellbookItem() {
|
||||
super(new Item.Settings()
|
||||
.maxCount(1)
|
||||
.group(ItemGroup.BREWING));
|
||||
Dispensable.setDispenseable(this, (source, stack) -> {
|
||||
Direction facing = source.getBlockState().get(DispenserBlock.FACING);
|
||||
BlockPos pos = source.getBlockPos().offset(facing);
|
||||
|
||||
setDispenseable();
|
||||
int yaw = facing.getOpposite().getHorizontal() * 90;
|
||||
placeBook(source.getWorld(), pos.getX(), pos.getY(), pos.getZ(), yaw);
|
||||
stack.decrement(1);
|
||||
|
||||
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,30 +69,6 @@ public class SpellbookItem extends BookItem implements Dispensable {
|
|||
|
||||
world.spawnEntity(book);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedActionResult<ItemStack> dispenseStack(BlockPointer source, ItemStack stack) {
|
||||
Direction facing = source.getBlockState().get(DispenserBlock.FACING);
|
||||
BlockPos pos = source.getBlockPos().offset(facing);
|
||||
|
||||
//0deg == SOUTH
|
||||
//90deg == WEST
|
||||
//180deg == NORTH
|
||||
//270deg == EAST
|
||||
|
||||
/*switch (facing) {
|
||||
case NORTH: yaw -= 90; break;
|
||||
case SOUTH: yaw += 90; break;
|
||||
case EAST: yaw += 180; break;
|
||||
default:
|
||||
}*/
|
||||
|
||||
int yaw = facing.getOpposite().getHorizontal() * 90;
|
||||
placeBook(source.getWorld(), pos.getX(), pos.getY(), pos.getZ(), yaw);
|
||||
stack.decrement(1);
|
||||
|
||||
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -6,15 +6,14 @@ import com.minelittlepony.unicopia.USounds;
|
|||
import com.minelittlepony.unicopia.block.UBlocks;
|
||||
import com.minelittlepony.unicopia.entity.UEntities;
|
||||
import com.minelittlepony.unicopia.magic.spell.ScorchSpell;
|
||||
import com.minelittlepony.unicopia.toxin.ToxicBlockItem;
|
||||
import com.minelittlepony.unicopia.toxin.ToxicItem;
|
||||
import com.minelittlepony.unicopia.toxin.Toxicity;
|
||||
import com.minelittlepony.unicopia.toxin.Toxin;
|
||||
import com.minelittlepony.unicopia.toxin.Toxics;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.Item.Settings;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.item.AliasedBlockItem;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.FoodComponent;
|
||||
|
@ -182,6 +181,8 @@ public interface UItems {
|
|||
// FurnaceRecipes.instance().addSmeltingRecipe(new ItemStack(zap_apple), new ItemStack(cooked_zap_apple), 0.1F);
|
||||
// FurnaceRecipes.instance().addSmeltingRecipe(new ItemStack(juice), new ItemStack(burned_juice), 0);
|
||||
// FurnaceRecipes.instance().addSmeltingRecipe(new ItemStack(cuccoon), new ItemStack(chitin_shell), 0.3F);
|
||||
|
||||
Toxics.bootstrap();
|
||||
}
|
||||
|
||||
interface VanillaOverrides {
|
||||
|
@ -190,63 +191,6 @@ public interface UItems {
|
|||
|
||||
AppleItem APPLE = register(new AppleItem(FoodComponents.APPLE), Items.APPLE);
|
||||
|
||||
Item GRASS = register(new ToxicBlockItem(Blocks.GRASS, new Settings()
|
||||
.food(UFoodComponents.RANDOM_FOLIAGE)
|
||||
.group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD.and(Toxin.NAUSEA)), Items.GRASS);
|
||||
Item FERN = register(new ToxicBlockItem(Blocks.FERN, new Settings()
|
||||
.food(UFoodComponents.RANDOM_FOLIAGE)
|
||||
.group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SEVERE, Toxin.FOOD.and(Toxin.STRENGTH)), Items.FERN);
|
||||
Item DEAD_BUSH = register(new ToxicBlockItem(Blocks.DEAD_BUSH, new Settings()
|
||||
.food(UFoodComponents.RANDOM_FOLIAGE)
|
||||
.group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SEVERE, Toxin.FOOD.and(Toxin.NAUSEA)), Items.DEAD_BUSH);
|
||||
|
||||
Item DANDELION = register(new ToxicBlockItem(Blocks.DANDELION, new Settings()
|
||||
.food(UFoodComponents.RANDOM_FOLIAGE)
|
||||
.group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.DANDELION);
|
||||
Item POPPY = register(new ToxicBlockItem(Blocks.POPPY, new Settings()
|
||||
.food(UFoodComponents.RANDOM_FOLIAGE)
|
||||
.group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SEVERE, Toxin.FOOD), Items.POPPY);
|
||||
Item BLUE_ORCHID = register(new ToxicBlockItem(Blocks.BLUE_ORCHID, new Settings()
|
||||
.food(UFoodComponents.RANDOM_FOLIAGE)
|
||||
.group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.BLUE_ORCHID);
|
||||
Item ALLIUM = register(new ToxicBlockItem(Blocks.ALLIUM, new Settings()
|
||||
.food(UFoodComponents.RANDOM_FOLIAGE)
|
||||
.group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.FAIR, Toxin.FOOD), Items.ALLIUM);
|
||||
Item AZUER_BLUET = register(new ToxicBlockItem(Blocks.AZURE_BLUET, new Settings()
|
||||
.food(UFoodComponents.RANDOM_FOLIAGE)
|
||||
.group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD.and(Toxin.RADIOACTIVITY)), Items.AZURE_BLUET);
|
||||
Item RED_TULIP = register(new ToxicBlockItem(Blocks.RED_TULIP, new Settings()
|
||||
.food(UFoodComponents.RANDOM_FOLIAGE)
|
||||
.group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.RED_TULIP);
|
||||
Item ORANGE_TULIP = register(new ToxicBlockItem(Blocks.ORANGE_TULIP, new Settings()
|
||||
.food(UFoodComponents.RANDOM_FOLIAGE)
|
||||
.group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.ORANGE_TULIP);
|
||||
Item WHITE_TULIP = register(new ToxicBlockItem(Blocks.WHITE_TULIP, new Settings()
|
||||
.food(UFoodComponents.RANDOM_FOLIAGE)
|
||||
.group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.FAIR, Toxin.FOOD), Items.WHITE_TULIP);
|
||||
Item PINK_TULIP = register(new ToxicBlockItem(Blocks.PINK_TULIP, new Settings()
|
||||
.food(UFoodComponents.RANDOM_FOLIAGE)
|
||||
.group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.PINK_TULIP);
|
||||
Item OXEYE_DAISY = register(new ToxicBlockItem(Blocks.OXEYE_DAISY, new Settings()
|
||||
.food(UFoodComponents.RANDOM_FOLIAGE)
|
||||
.group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SEVERE, Toxin.FOOD.and(Toxin.BLINDNESS)), Items.OXEYE_DAISY);
|
||||
Item CORNFLOWER = register(new ToxicBlockItem(Blocks.CORNFLOWER, new Settings()
|
||||
.food(UFoodComponents.RANDOM_FOLIAGE)
|
||||
.group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.CORNFLOWER);
|
||||
|
||||
Item ROSE_BUSH = register(new ToxicBlockItem(Blocks.ROSE_BUSH, new Settings()
|
||||
.food(UFoodComponents.RANDOM_FOLIAGE)
|
||||
.group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD.and(Toxin.DAMAGE)), Items.ROSE_BUSH);
|
||||
Item PEONY = register(new ToxicBlockItem(Blocks.PEONY, new Settings()
|
||||
.food(UFoodComponents.RANDOM_FOLIAGE)
|
||||
.group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.PEONY);
|
||||
Item TALL_GRASS = register(new ToxicBlockItem(Blocks.TALL_GRASS, new Settings()
|
||||
.food(UFoodComponents.RANDOM_FOLIAGE)
|
||||
.group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SAFE, Toxin.FOOD), Items.TALL_GRASS);
|
||||
Item LARGE_FERN = register(new ToxicBlockItem(Blocks.LARGE_FERN, new Settings()
|
||||
.food(UFoodComponents.RANDOM_FOLIAGE)
|
||||
.group(ItemGroup.DECORATIONS), UseAction.EAT, Toxicity.SEVERE, Toxin.FOOD.and(Toxin.DAMAGE)), Items.LARGE_FERN);
|
||||
|
||||
static <T extends Item> T register(T newItem, Item oldItem) {
|
||||
return Registry.ITEM.set(Registry.ITEM.getRawId(oldItem), Registry.ITEM.getId(oldItem), newItem);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public enum Affinity {
|
|||
}
|
||||
|
||||
public Text getName() {
|
||||
Text text = new TranslatableText("affinity." + getTranslationKey() + ".name");
|
||||
Text text = new TranslatableText("affinity." + getTranslationKey());
|
||||
text.getStyle().setColor(getColourCode());
|
||||
return text;
|
||||
}
|
||||
|
|
|
@ -12,26 +12,43 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.math.BlockPointer;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
public interface Dispensable {
|
||||
/**
|
||||
* Enables dispensing behaviours for this item.
|
||||
*/
|
||||
default Item setDispenseable() {
|
||||
DispenserBlock.registerBehavior((Item)this, new ItemDispenserBehavior() {
|
||||
static DispenserBehavior setDispenseable(Item item, Dispensable action) {
|
||||
ItemDispenserBehavior behaviour = new ItemDispenserBehavior() {
|
||||
private ActionResult result;
|
||||
@Override
|
||||
protected ItemStack dispenseSilently(BlockPointer source, ItemStack stack) {
|
||||
TypedActionResult<ItemStack> result = dispenseStack(source, stack);
|
||||
TypedActionResult<ItemStack> result = action.dispenseStack(source, stack);
|
||||
this.result = result.getResult();
|
||||
|
||||
if (result.getResult() != ActionResult.SUCCESS) {
|
||||
if (this.result != ActionResult.SUCCESS) {
|
||||
return super.dispenseSilently(source, stack);
|
||||
}
|
||||
|
||||
return result.getValue();
|
||||
}
|
||||
});
|
||||
|
||||
return (Item)this;
|
||||
@Override
|
||||
protected void playSound(BlockPointer pointer) {
|
||||
if (result != ActionResult.PASS) {
|
||||
super.playSound(pointer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void spawnParticles(BlockPointer pointer, Direction side) {
|
||||
if (result != ActionResult.PASS) {
|
||||
super.spawnParticles(pointer, side);
|
||||
}
|
||||
}
|
||||
};
|
||||
DispenserBlock.registerBehavior(item, behaviour);
|
||||
return behaviour;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,7 +56,7 @@ public interface Dispensable {
|
|||
*/
|
||||
TypedActionResult<ItemStack> dispenseStack(BlockPointer source, ItemStack stack);
|
||||
|
||||
default Optional<DispenserBehavior> getBehavior(ItemStack stack) {
|
||||
static Optional<DispenserBehavior> getBehavior(ItemStack stack) {
|
||||
return Optional.ofNullable(DispenserAccess.INSTANCE.getBehaviorForItem(stack));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
package com.minelittlepony.unicopia.mixin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import com.minelittlepony.unicopia.toxin.Toxic;
|
||||
import com.minelittlepony.unicopia.toxin.ToxicHolder;
|
||||
|
||||
import net.minecraft.client.item.TooltipContext;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.BlockItem;
|
||||
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;
|
||||
|
||||
@Mixin(BlockItem.class)
|
||||
abstract class MixinBlockItem extends Item implements ToxicHolder {
|
||||
public MixinBlockItem() {super(null); }
|
||||
|
||||
@Nullable
|
||||
private Toxic toxic;
|
||||
|
||||
@Override
|
||||
public void setToxic(Toxic toxic) {
|
||||
this.toxic = toxic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UseAction getUseAction(ItemStack stack) {
|
||||
if (toxic != null) {
|
||||
return toxic.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));
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
||||
if (toxic == null) {
|
||||
return super.use(world, player, hand);
|
||||
}
|
||||
return toxic.use(world, player, hand, () -> super.use(world, player, hand));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.minelittlepony.unicopia.mixin;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import com.minelittlepony.unicopia.toxin.ToxicHolder;
|
||||
|
||||
import net.minecraft.item.FoodComponent;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
@Mixin(Item.class)
|
||||
abstract class MixinItem implements ToxicHolder {
|
||||
@Override
|
||||
@Accessor("foodComponent")
|
||||
public abstract void setFood(FoodComponent food);
|
||||
}
|
|
@ -25,6 +25,10 @@ public class Toxic {
|
|||
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(Item item, UseAction action, Toxin toxin, Function<ItemStack, Toxicity> toxicity) {
|
||||
this.item = item;
|
||||
this.action = action;
|
||||
|
|
|
@ -1,48 +1,18 @@
|
|||
package com.minelittlepony.unicopia.toxin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.item.TooltipContext;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.BlockItem;
|
||||
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 ToxicBlockItem extends BlockItem {
|
||||
|
||||
private final Toxic toxic;
|
||||
public ToxicBlockItem(Block block, Settings settings, Toxic toxic) {
|
||||
super(block, settings);
|
||||
((ToxicHolder)this).setToxic(toxic);
|
||||
}
|
||||
|
||||
public ToxicBlockItem(Block block, Settings settings, UseAction action, Toxicity toxicity, Toxin toxin) {
|
||||
super(block, settings);
|
||||
toxic = new Toxic(this, action, toxin, stack -> 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));
|
||||
((ToxicHolder)this).setToxic(new Toxic(this, action, toxin, toxicity));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package com.minelittlepony.unicopia.toxin;
|
||||
|
||||
import net.minecraft.item.FoodComponent;
|
||||
|
||||
public interface ToxicHolder {
|
||||
void setFood(FoodComponent food);
|
||||
void setToxic(Toxic toxic);
|
||||
}
|
42
src/main/java/com/minelittlepony/unicopia/toxin/Toxics.java
Normal file
42
src/main/java/com/minelittlepony/unicopia/toxin/Toxics.java
Normal file
|
@ -0,0 +1,42 @@
|
|||
package com.minelittlepony.unicopia.toxin;
|
||||
|
||||
import com.minelittlepony.unicopia.item.UFoodComponents;
|
||||
|
||||
import net.minecraft.item.FoodComponent;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.util.UseAction;
|
||||
|
||||
public interface Toxics {
|
||||
|
||||
Toxic GRASS = register(Items.GRASS, UFoodComponents.RANDOM_FOLIAGE, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD.and(Toxin.NAUSEA));
|
||||
Toxic FERN = register(Items.FERN, UFoodComponents.RANDOM_FOLIAGE, UseAction.EAT, Toxicity.SEVERE, Toxin.FOOD.and(Toxin.STRENGTH));
|
||||
Toxic DEAD_BUSH = register(Items.DEAD_BUSH, UFoodComponents.RANDOM_FOLIAGE, UseAction.EAT, Toxicity.SEVERE, Toxin.FOOD.and(Toxin.NAUSEA));
|
||||
|
||||
Toxic DANDELION = register(Items.DANDELION, UFoodComponents.RANDOM_FOLIAGE, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD);
|
||||
Toxic POPPY = register(Items.POPPY, UFoodComponents.RANDOM_FOLIAGE, UseAction.EAT, Toxicity.SEVERE, Toxin.FOOD);
|
||||
Toxic BLUE_ORCHID = register(Items.BLUE_ORCHID, UFoodComponents.RANDOM_FOLIAGE, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD);
|
||||
Toxic ALLIUM = register(Items.ALLIUM, UFoodComponents.RANDOM_FOLIAGE, UseAction.EAT, Toxicity.FAIR, Toxin.FOOD);
|
||||
Toxic AZUER_BLUET = register(Items.AZURE_BLUET, UFoodComponents.RANDOM_FOLIAGE, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD.and(Toxin.RADIOACTIVITY));
|
||||
Toxic RED_TULIP = register(Items.RED_TULIP, UFoodComponents.RANDOM_FOLIAGE, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD);
|
||||
Toxic ORANGE_TULIP = register(Items.ORANGE_TULIP, UFoodComponents.RANDOM_FOLIAGE, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD);
|
||||
Toxic WHITE_TULIP = register(Items.WHITE_TULIP, UFoodComponents.RANDOM_FOLIAGE, UseAction.EAT, Toxicity.FAIR, Toxin.FOOD);
|
||||
Toxic PINK_TULIP = register(Items.PINK_TULIP, UFoodComponents.RANDOM_FOLIAGE, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD);
|
||||
Toxic OXEYE_DAISY = register(Items.OXEYE_DAISY, UFoodComponents.RANDOM_FOLIAGE, UseAction.EAT, Toxicity.SEVERE, Toxin.FOOD.and(Toxin.BLINDNESS));
|
||||
Toxic CORNFLOWER = register(Items.CORNFLOWER, UFoodComponents.RANDOM_FOLIAGE, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD);
|
||||
|
||||
Toxic ROSE_BUSH = register(Items.ROSE_BUSH, UFoodComponents.RANDOM_FOLIAGE, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD.and(Toxin.DAMAGE));
|
||||
Toxic PEONY = register(Items.PEONY, UFoodComponents.RANDOM_FOLIAGE, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD);
|
||||
Toxic TALL_GRASS = register(Items.TALL_GRASS, UFoodComponents.RANDOM_FOLIAGE, UseAction.EAT, Toxicity.SAFE, Toxin.FOOD);
|
||||
Toxic LARGE_FERN = register(Items.LARGE_FERN, UFoodComponents.RANDOM_FOLIAGE, UseAction.EAT, Toxicity.SEVERE, Toxin.FOOD.and(Toxin.DAMAGE));
|
||||
|
||||
static void bootstrap() {}
|
||||
|
||||
static Toxic register(Item target, FoodComponent food, UseAction action, Toxicity toxicity, Toxin toxin) {
|
||||
Toxic toxic = new Toxic(target, action, toxin, toxicity);
|
||||
ToxicHolder holder = (ToxicHolder)target;
|
||||
holder.setFood(food);
|
||||
holder.setToxic(toxic);
|
||||
return toxic;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue