Removed the override for minecraft:stick. Use Shills instead (name wip)

This commit is contained in:
Sollace 2019-03-18 15:22:22 +02:00
parent 6ad1d099e0
commit 8d67b60e64
8 changed files with 89 additions and 36 deletions

View file

@ -2,8 +2,6 @@ package com.minelittlepony.unicopia.block;
import java.util.Random;
import com.minelittlepony.unicopia.init.UItems;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
@ -68,7 +66,7 @@ public class BlockStick extends Block implements IPlantable {
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
return UItems.stick;
return Items.STICK;
}
@Override

View file

@ -133,7 +133,7 @@ public class BlockTomatoPlant extends BlockCrops {
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
Random rand = world instanceof World ? ((World)world).rand : RANDOM;
drops.add(new ItemStack(UItems.stick, 1, 0));
drops.add(new ItemStack(Items.STICK, 1, 0));
Item item = getItemDropped(state, rand, fortune);
if (item != Items.AIR) {

View file

@ -1,5 +1,7 @@
package com.minelittlepony.unicopia.init;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.CloudType;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.block.BlockAlfalfa;
@ -135,4 +137,15 @@ public class UBlocks {
return ColorizerFoliage.getFoliageColorBasic();
}, apple_leaves);
}
public static class Shills {
@Nullable
public static Block getShill(Block blockIn) {
if (blockIn == Blocks.FLOWER_POT) {
return flower_pot;
}
return null;
}
}
}

View file

@ -14,7 +14,6 @@ import com.minelittlepony.unicopia.item.ItemRottenApple;
import com.minelittlepony.unicopia.item.ItemSpell;
import com.minelittlepony.unicopia.item.ItemSpellbook;
import com.minelittlepony.unicopia.item.ItemStaff;
import com.minelittlepony.unicopia.item.ItemStick;
import com.minelittlepony.unicopia.item.ItemTomato;
import com.minelittlepony.unicopia.item.ItemTomatoSeeds;
import com.minelittlepony.unicopia.item.ItemZapApple;
@ -22,6 +21,8 @@ import com.minelittlepony.unicopia.item.UItemBlock;
import com.minelittlepony.unicopia.item.UItemDecoration;
import com.minelittlepony.unicopia.item.UItemSlab;
import com.minelittlepony.unicopia.item.URecord;
import com.minelittlepony.unicopia.item.override.ItemShear;
import com.minelittlepony.unicopia.item.override.ItemStick;
import com.minelittlepony.unicopia.spell.SpellRegistry;
import com.minelittlepony.unicopia.spell.SpellScorch;
@ -47,6 +48,8 @@ import net.minecraftforge.registries.IForgeRegistry;
import static com.minelittlepony.unicopia.Predicates.*;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.UClient;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.edibles.BushToxicityDeterminent;
@ -155,7 +158,6 @@ public class UItems {
.setRegistryName(Unicopia.MODID, "alfalfa_seeds")
.setCreativeTab(CreativeTabs.MATERIALS);
public static final ItemStick stick = new ItemStick();
public static final Item enchanted_torch = new ItemBlock(UBlocks.enchanted_torch)
.setRegistryName(Unicopia.MODID, "enchanted_torch");
@ -236,7 +238,6 @@ public class UItems {
static void init(IForgeRegistry<Item> registry) {
RegistryLockSpinner.open(Item.REGISTRY, Items.class, r -> r
.replace(Items.APPLE, red_apple)
.replace(Items.STICK, stick)
.replace(Item.getItemFromBlock(Blocks.TALLGRASS), tall_grass)
.replace(Item.getItemFromBlock(Blocks.DOUBLE_PLANT), double_plant)
.replace(Item.getItemFromBlock(Blocks.YELLOW_FLOWER), yellow_flower)
@ -330,4 +331,22 @@ public class UItems {
return 0xffffff;
}, spell, curse);
}
public static class Shills {
private static final ItemStick stick = new ItemStick();
private static final ItemShear shears = new ItemShear();
@Nullable
public static Item getShill(Item itemIn) {
if (itemIn == Items.SHEARS) {
return shears;
}
if (itemIn == Items.STICK) {
return stick;
}
return null;
}
}
}

View file

@ -0,0 +1,32 @@
package com.minelittlepony.unicopia.item.override;
import com.minelittlepony.unicopia.init.UItems;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemShears;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class ItemShear extends ItemShears {
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
IBlockState state = world.getBlockState(pos);
if (UItems.moss.tryConvert(world, state, pos, player)) {
ItemStack stack = player.getHeldItem(hand);
if (!player.isCreative()) {
stack.damageItem(1, player);
}
return EnumActionResult.SUCCESS;
}
return EnumActionResult.PASS;
}
}

View file

@ -1,15 +1,13 @@
package com.minelittlepony.unicopia.item;
package com.minelittlepony.unicopia.item.override;
import com.minelittlepony.unicopia.init.UBlocks;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemSeeds;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
@ -18,16 +16,7 @@ import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class ItemStick extends ItemSeeds {
public ItemStick() {
super(UBlocks.tomato_plant, Blocks.FARMLAND);
setFull3D();
setTranslationKey("stick");
setCreativeTab(CreativeTabs.MATERIALS);
}
public class ItemStick extends Item {
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack itemstack = player.getHeldItem(hand);
@ -45,7 +34,10 @@ public class ItemStick extends ItemSeeds {
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos.up(), itemstack);
}
itemstack.shrink(1);
if (!(player instanceof EntityPlayer && ((EntityPlayer)player).capabilities.isCreativeMode)) {
itemstack.shrink(1);
}
return EnumActionResult.SUCCESS;
}

View file

@ -12,9 +12,10 @@ import net.minecraft.block.BlockTallGrass;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -38,23 +39,21 @@ public class BlockInteractions {
return true;
}
public EnumActionResult onBlockInteract(World world, IBlockState state, BlockPos pos, EntityPlayer player, ItemStack stack, EnumHand hand) {
public EnumActionResult onBlockInteract(World world, IBlockState state, BlockPos pos, EntityPlayer player, ItemStack stack, EnumFacing facing, EnumHand hand) {
Item shill = UItems.Shills.getShill(stack.getItem());
if (stack.getItem() == Items.SHEARS) {
if (UItems.moss.tryConvert(world, state, pos, player)) {
if (shill != null) {
EnumActionResult result = shill.onItemUse(player, world, pos, hand, facing, 0, 0, 0);
if (!player.isCreative()) {
stack.damageItem(1, player);
}
return EnumActionResult.SUCCESS;
if (result == EnumActionResult.SUCCESS) {
return result;
}
}
if (state.getBlock() == Blocks.FLOWER_POT) {
if (UBlocks.flower_pot.onBlockActivated(world, pos, state, player, hand, player.getHorizontalFacing(), 0.5F, 0.5F, 0.5F)) {
return EnumActionResult.SUCCESS;
}
Block shillBlock = UBlocks.Shills.getShill(state.getBlock());
if (shillBlock != null && shillBlock.onBlockActivated(world, pos, state, player, hand, player.getHorizontalFacing(), 0.5F, 0.5F, 0.5F)) {
return EnumActionResult.SUCCESS;
}
return EnumActionResult.PASS;

View file

@ -23,7 +23,7 @@ public class Hooks {
}
EnumActionResult result = UWorld.instance().getBlocks().onBlockInteract(
event.getWorld(), event.getWorld().getBlockState(event.getPos()), event.getPos(), event.getEntityPlayer(), event.getItemStack(), event.getHand());
event.getWorld(), event.getWorld().getBlockState(event.getPos()), event.getPos(), event.getEntityPlayer(), event.getItemStack(), event.getFace(), event.getHand());
if (result != EnumActionResult.PASS) {
event.setCanceled(true);