mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-01 19:46:42 +01:00
Changed how overrides are done so they break fewer things
This commit is contained in:
parent
17e036a49c
commit
dcf41398a1
8 changed files with 63 additions and 17 deletions
|
@ -14,6 +14,7 @@ import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
|
|
||||||
|
@ -25,7 +26,7 @@ public final class TreeType {
|
||||||
public static final TreeType OAK = new TreeType("oak", new Weighted<Supplier<ItemStack>>()
|
public static final TreeType OAK = new TreeType("oak", new Weighted<Supplier<ItemStack>>()
|
||||||
.put(1, () -> new ItemStack(UItems.ROTTEN_APPLE))
|
.put(1, () -> new ItemStack(UItems.ROTTEN_APPLE))
|
||||||
.put(2, () -> new ItemStack(UItems.GREEN_APPLE))
|
.put(2, () -> new ItemStack(UItems.GREEN_APPLE))
|
||||||
.put(3, () -> new ItemStack(UItems.VanillaOverrides.APPLE)), Blocks.OAK_LOG, Blocks.OAK_LEAVES);
|
.put(3, () -> new ItemStack(Items.APPLE)), Blocks.OAK_LOG, Blocks.OAK_LEAVES);
|
||||||
public static final TreeType BIRCH = new TreeType("birch", new Weighted<Supplier<ItemStack>>()
|
public static final TreeType BIRCH = new TreeType("birch", new Weighted<Supplier<ItemStack>>()
|
||||||
.put(1, () -> new ItemStack(UItems.ROTTEN_APPLE))
|
.put(1, () -> new ItemStack(UItems.ROTTEN_APPLE))
|
||||||
.put(2, () -> new ItemStack(UItems.SWEET_APPLE))
|
.put(2, () -> new ItemStack(UItems.SWEET_APPLE))
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class AppleItem extends Item implements ItemEntityCapabilities.TickableIt
|
||||||
public ActionResult onGroundTick(IItemEntity item) {
|
public ActionResult onGroundTick(IItemEntity item) {
|
||||||
ItemEntity entity = item.get().getOwner();
|
ItemEntity entity = item.get().getOwner();
|
||||||
|
|
||||||
if (!entity.removed && item.getAge() > item.getPickupDelay()) {
|
if (!entity.removed && item.getPickupDelay() == 0 && item.getAge() > 200230 && entity.world.random.nextInt(200) < 10) {
|
||||||
|
|
||||||
if (!entity.world.isClient) {
|
if (!entity.world.isClient) {
|
||||||
entity.remove();
|
entity.remove();
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class ExtendedShearsItem extends ShearsItem {
|
||||||
public ExtendedShearsItem(Settings settings) {
|
public ExtendedShearsItem(Settings settings) {
|
||||||
super(settings);
|
super(settings);
|
||||||
final Optional<DispenserBehavior> vanillaDispenserBehaviour = Dispensable.getBehavior(new ItemStack(Items.SHEARS));
|
final Optional<DispenserBehavior> vanillaDispenserBehaviour = Dispensable.getBehavior(new ItemStack(Items.SHEARS));
|
||||||
DispenserBlock.registerBehavior(Items.SHEARS, Dispensable.setDispenseable(this, (source, stack) -> {
|
/*DispenserBlock.registerBehavior(Items.SHEARS,*/ Dispensable.setDispenseable(this, (source, stack) -> {
|
||||||
|
|
||||||
BlockPos pos = source.getBlockPos().offset(source.getBlockState().get(DispenserBlock.FACING));
|
BlockPos pos = source.getBlockPos().offset(source.getBlockState().get(DispenserBlock.FACING));
|
||||||
World w = source.getWorld();
|
World w = source.getWorld();
|
||||||
|
@ -38,7 +38,7 @@ public class ExtendedShearsItem extends ShearsItem {
|
||||||
return TypedActionResult.pass(action.dispense(source, stack));
|
return TypedActionResult.pass(action.dispense(source, stack));
|
||||||
})
|
})
|
||||||
.orElseGet(() -> TypedActionResult.fail(stack));
|
.orElseGet(() -> TypedActionResult.fail(stack));
|
||||||
}));
|
})/*)*/;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -163,6 +163,9 @@ public interface UItems {
|
||||||
Item BUTTERFLY_SPAWN_EGG = register(new SpawnEggItem(UEntities.BUTTERFLY, 0x222200, 0xaaeeff, new Settings().group(ItemGroup.MISC)), "butterfly_spawn_egg");
|
Item BUTTERFLY_SPAWN_EGG = register(new SpawnEggItem(UEntities.BUTTERFLY, 0x222200, 0xaaeeff, new Settings().group(ItemGroup.MISC)), "butterfly_spawn_egg");
|
||||||
|
|
||||||
static <T extends Item> T register(T item, String name) {
|
static <T extends Item> T register(T item, String name) {
|
||||||
|
if (item instanceof BlockItem) {
|
||||||
|
((BlockItem)item).appendBlocks(Item.BLOCK_ITEMS, item);
|
||||||
|
}
|
||||||
return Registry.ITEM.add(new Identifier("unicopia", name), item);
|
return Registry.ITEM.add(new Identifier("unicopia", name), item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,15 +184,4 @@ public interface UItems {
|
||||||
|
|
||||||
Toxics.bootstrap();
|
Toxics.bootstrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
interface VanillaOverrides {
|
|
||||||
StickItem STICK = register(new StickItem(new Item.Settings().group(ItemGroup.MATERIALS)), Items.STICK);
|
|
||||||
ExtendedShearsItem SHEARS = register(new ExtendedShearsItem(new Item.Settings().maxDamage(238).group(ItemGroup.TOOLS)), Items.SHEARS);
|
|
||||||
|
|
||||||
AppleItem APPLE = register(new AppleItem(new Item.Settings().group(ItemGroup.FOOD).food(FoodComponents.APPLE)), Items.APPLE);
|
|
||||||
|
|
||||||
static <T extends Item> T register(T newItem, Item oldItem) {
|
|
||||||
return Registry.ITEM.set(Registry.ITEM.getRawId(oldItem), Registry.ITEM.getId(oldItem), newItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.minelittlepony.unicopia.item;
|
||||||
|
|
||||||
|
import net.minecraft.item.FoodComponents;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemGroup;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.registry.Registry;
|
||||||
|
import net.minecraft.util.registry.SimpleRegistry;
|
||||||
|
|
||||||
|
public final class VanillaOverrides {
|
||||||
|
|
||||||
|
public static final Registry<Item> REGISTRY = new SimpleRegistry<>();
|
||||||
|
|
||||||
|
private static <T extends Item> T register(String name, T newItem) {
|
||||||
|
return Registry.register(REGISTRY, new Identifier(name), newItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
register("stick", new StickItem(new Item.Settings().group(ItemGroup.MATERIALS)));
|
||||||
|
register("shears", new ExtendedShearsItem(new Item.Settings().maxDamage(238).group(ItemGroup.TOOLS)));
|
||||||
|
register("apple", new AppleItem(new Item.Settings().group(ItemGroup.FOOD).food(FoodComponents.APPLE)));
|
||||||
|
}
|
||||||
|
}
|
|
@ -34,7 +34,7 @@ import net.minecraft.world.World;
|
||||||
public class ZapAppleItem extends AppleItem {
|
public class ZapAppleItem extends AppleItem {
|
||||||
|
|
||||||
private static final List<Item> ALIASABLE_ITEMS = Lists.newArrayList(
|
private static final List<Item> ALIASABLE_ITEMS = Lists.newArrayList(
|
||||||
UItems.VanillaOverrides.APPLE,
|
Items.APPLE,
|
||||||
UItems.GREEN_APPLE,
|
UItems.GREEN_APPLE,
|
||||||
UItems.SWEET_APPLE,
|
UItems.SWEET_APPLE,
|
||||||
UItems.SOUR_APPLE,
|
UItems.SOUR_APPLE,
|
||||||
|
@ -96,7 +96,11 @@ public class ZapAppleItem extends AppleItem {
|
||||||
public void appendStacks(ItemGroup tab, DefaultedList<ItemStack> items) {
|
public void appendStacks(ItemGroup tab, DefaultedList<ItemStack> items) {
|
||||||
super.appendStacks(tab, items);
|
super.appendStacks(tab, items);
|
||||||
if (isIn(tab)) {
|
if (isIn(tab)) {
|
||||||
ALIASABLE_ITEMS.forEach(item -> items.add(new ItemStack(item)));
|
ALIASABLE_ITEMS.forEach(item -> {
|
||||||
|
ItemStack stack = new ItemStack(this);
|
||||||
|
stack.getOrCreateTag().putString("appearance", Registry.ITEM.getId(item).toString());
|
||||||
|
items.add(stack);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.minelittlepony.unicopia.mixin;
|
||||||
|
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||||
|
|
||||||
|
import com.minelittlepony.unicopia.item.VanillaOverrides;
|
||||||
|
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
@Mixin(Items.class)
|
||||||
|
abstract class MixinItems {
|
||||||
|
@ModifyVariable(method = "register(Lnet/minecraft/util/Identifier;Lnet/minecraft/item/Item;)Lnet/minecraft/item/Item;",
|
||||||
|
at = @At("HEAD"),
|
||||||
|
index = 1,
|
||||||
|
argsOnly = true)
|
||||||
|
private static Item modifyItem(Item item, Identifier id, Item itemAlso) {
|
||||||
|
if (VanillaOverrides.REGISTRY.containsId(id)) {
|
||||||
|
return VanillaOverrides.REGISTRY.get(id);
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,6 +10,7 @@
|
||||||
"MixinFarmlandBlock",
|
"MixinFarmlandBlock",
|
||||||
"MixinHoeItem",
|
"MixinHoeItem",
|
||||||
"MixinItem",
|
"MixinItem",
|
||||||
|
"MixinItems",
|
||||||
"MixinItemEntity",
|
"MixinItemEntity",
|
||||||
"MixinLivingEntity",
|
"MixinLivingEntity",
|
||||||
"MixinPlayerEntity",
|
"MixinPlayerEntity",
|
||||||
|
|
Loading…
Reference in a new issue