mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Added moss
This commit is contained in:
parent
ff7c400885
commit
b9400cf805
18 changed files with 315 additions and 61 deletions
|
@ -1,11 +1,13 @@
|
|||
package com.minelittlepony.unicopia.block;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.minelittlepony.unicopia.CloudType;
|
||||
import com.minelittlepony.unicopia.init.UBlocks;
|
||||
import com.minelittlepony.unicopia.item.ItemMoss;
|
||||
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -39,6 +41,8 @@ public class BlockCloud extends Block implements ICloudBlock, ITillable {
|
|||
setResistance(1.0F);
|
||||
setSoundType(SoundType.CLOTH);
|
||||
setLightOpacity(20);
|
||||
setTickRandomly(true);
|
||||
|
||||
useNeighborBrightness = true;
|
||||
|
||||
this.variant = variant;
|
||||
|
@ -54,6 +58,20 @@ public class BlockCloud extends Block implements ICloudBlock, ITillable {
|
|||
return variant != CloudType.NORMAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
|
||||
if (rand.nextInt(10) == 0) {
|
||||
pos = pos.offset(EnumFacing.random(rand), 1 + rand.nextInt(2));
|
||||
state = world.getBlockState(pos);
|
||||
|
||||
IBlockState converted = ItemMoss.affected.getInverse().getConverted(state);
|
||||
|
||||
if (!state.equals(converted)) {
|
||||
world.setBlockState(pos, converted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
//Push player out of block
|
||||
public boolean isFullCube(IBlockState state) {
|
||||
|
|
|
@ -46,6 +46,7 @@ public abstract class BlockCloudSlab<T extends Block & ICloudBlock> extends Bloc
|
|||
setSoundType(SoundType.CLOTH);
|
||||
setLightOpacity(20);
|
||||
setTranslationKey(name);
|
||||
setTickRandomly(modelBlock.getTickRandomly());
|
||||
setRegistryName(domain, name);
|
||||
|
||||
useNeighborBrightness = true;
|
||||
|
@ -83,6 +84,11 @@ public abstract class BlockCloudSlab<T extends Block & ICloudBlock> extends Bloc
|
|||
return isDouble() && modelBlock.isNormalCube(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
|
||||
modelBlock.updateTick(world, pos, state, rand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRenderLayer getRenderLayer() {
|
||||
return modelBlock.getRenderLayer();
|
||||
|
|
|
@ -33,6 +33,9 @@ public class BlockCloudStairs extends BlockStairs implements ICloudBlock {
|
|||
setRegistryName(domain, name);
|
||||
theBlock = inherited.getBlock();
|
||||
theState = inherited;
|
||||
|
||||
setTickRandomly(theBlock.getTickRandomly());
|
||||
|
||||
useNeighborBrightness = true;
|
||||
|
||||
fullBlock = isOpaqueCube(inherited);
|
||||
|
|
|
@ -4,7 +4,6 @@ import com.minelittlepony.unicopia.CloudType;
|
|||
import com.minelittlepony.unicopia.Predicates;
|
||||
import com.minelittlepony.unicopia.UClient;
|
||||
import com.minelittlepony.unicopia.forgebullshit.FUF;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockBed;
|
||||
import net.minecraft.block.BlockChest;
|
||||
|
|
|
@ -2,11 +2,9 @@ package com.minelittlepony.unicopia.edibles;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.minelittlepony.unicopia.Race;
|
||||
import com.minelittlepony.unicopia.forgebullshit.IMultiItem;
|
||||
import com.minelittlepony.unicopia.init.UEffects;
|
||||
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
|
||||
|
||||
|
@ -29,33 +27,19 @@ import net.minecraft.util.EnumHand;
|
|||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemEdible extends ItemFood implements IEdible, IMultiItem {
|
||||
|
||||
private String translationKey;
|
||||
|
||||
private final IEdible toxicityDeterminant;
|
||||
public abstract class ItemEdible extends ItemFood implements IEdible {
|
||||
|
||||
private EnumAction useAction = EnumAction.EAT;
|
||||
|
||||
public ItemEdible(@Nonnull IEdible mapper) {
|
||||
super(1, 0, false);
|
||||
|
||||
toxicityDeterminant = mapper;
|
||||
public ItemEdible(int amount, int saturation, boolean isMeat) {
|
||||
super(amount, saturation, isMeat);
|
||||
}
|
||||
|
||||
public ItemEdible(String domain, String name, int amount, int saturation, @Nonnull IEdible mapper) {
|
||||
super(amount, saturation, false);
|
||||
public ItemEdible(String domain, String name, int amount, int saturation, boolean isMeat) {
|
||||
super(amount, saturation, isMeat);
|
||||
|
||||
setTranslationKey(name);
|
||||
setRegistryName(domain, name);
|
||||
|
||||
toxicityDeterminant = mapper;
|
||||
}
|
||||
|
||||
public Item setTranslationKey(String key) {
|
||||
translationKey = key;
|
||||
|
||||
return super.setTranslationKey(key);
|
||||
}
|
||||
|
||||
public Item setUseAction(EnumAction action) {
|
||||
|
@ -140,22 +124,5 @@ public class ItemEdible extends ItemFood implements IEdible, IMultiItem {
|
|||
} else if (toxicity.toxicWhenCooked()) {
|
||||
player.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 3, 1, false, false));
|
||||
}
|
||||
|
||||
toxicityDeterminant.addSecondaryEffects(player, toxicity, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Toxicity getToxicityLevel(ItemStack stack) {
|
||||
return toxicityDeterminant.getToxicityLevel(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getVariants() {
|
||||
return Toxicity.getVariants(translationKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean variantsAreHidden() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package com.minelittlepony.unicopia.edibles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import com.minelittlepony.unicopia.forgebullshit.IMultiItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class MultiItemEdible extends ItemEdible implements IMultiItem {
|
||||
|
||||
private String translationKey;
|
||||
|
||||
private final IEdible toxicityDeterminant;
|
||||
|
||||
public MultiItemEdible(@Nonnull IEdible mapper) {
|
||||
super(1, 0, false);
|
||||
|
||||
toxicityDeterminant = mapper;
|
||||
}
|
||||
|
||||
public MultiItemEdible(String domain, String name, int amount, int saturation, @Nonnull IEdible mapper) {
|
||||
super(domain, name, amount, saturation, false);
|
||||
|
||||
toxicityDeterminant = mapper;
|
||||
}
|
||||
|
||||
public Item setTranslationKey(String key) {
|
||||
translationKey = key;
|
||||
|
||||
return super.setTranslationKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSecondaryEffects(EntityPlayer player, Toxicity toxicity, ItemStack stack) {
|
||||
super.addSecondaryEffects(player, toxicity, stack);
|
||||
|
||||
toxicityDeterminant.addSecondaryEffects(player, toxicity, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Toxicity getToxicityLevel(ItemStack stack) {
|
||||
return toxicityDeterminant.getToxicityLevel(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getVariants() {
|
||||
return Toxicity.getVariants(translationKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean variantsAreHidden() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import com.minelittlepony.unicopia.item.ItemCereal;
|
|||
import com.minelittlepony.unicopia.item.ItemCloud;
|
||||
import com.minelittlepony.unicopia.item.ItemCurse;
|
||||
import com.minelittlepony.unicopia.item.ItemFruitLeaves;
|
||||
import com.minelittlepony.unicopia.item.ItemMoss;
|
||||
import com.minelittlepony.unicopia.item.ItemOfHolding;
|
||||
import com.minelittlepony.unicopia.item.ItemRottenApple;
|
||||
import com.minelittlepony.unicopia.item.ItemSpell;
|
||||
|
@ -48,7 +49,7 @@ import com.minelittlepony.unicopia.Unicopia;
|
|||
import com.minelittlepony.unicopia.edibles.BushToxicityDeterminent;
|
||||
import com.minelittlepony.unicopia.edibles.CookedToxicityDeterminent;
|
||||
import com.minelittlepony.unicopia.edibles.FlowerToxicityDeterminent;
|
||||
import com.minelittlepony.unicopia.edibles.ItemEdible;
|
||||
import com.minelittlepony.unicopia.edibles.MultiItemEdible;
|
||||
import com.minelittlepony.unicopia.edibles.Toxicity;
|
||||
import com.minelittlepony.unicopia.edibles.UItemFoodDelegate;
|
||||
import com.minelittlepony.unicopia.extern.Baubles;
|
||||
|
@ -113,6 +114,7 @@ public class UItems {
|
|||
public static final ItemSpellbook spellbook = new ItemSpellbook(Unicopia.MODID, "spellbook");
|
||||
public static final Item staff_meadow_brook = new ItemStaff(Unicopia.MODID, "staff_meadow_brook").setMaxDamage(2);
|
||||
|
||||
public static final ItemMoss moss = new ItemMoss(Unicopia.MODID, "moss");
|
||||
|
||||
public static final Item alfalfa_seeds = new ItemSeedFood(1, 4, UBlocks.alfalfa, Blocks.FARMLAND)
|
||||
.setTranslationKey("alfalfa_seeds")
|
||||
|
@ -140,7 +142,7 @@ public class UItems {
|
|||
|
||||
public static final Item double_plant = new UItemFoodDelegate(Blocks.DOUBLE_PLANT, stack ->
|
||||
BlockDoublePlant.EnumPlantType.byMetadata(stack.getMetadata()).getTranslationKey()
|
||||
).setFoodDelegate(new ItemEdible(new BushToxicityDeterminent()))
|
||||
).setFoodDelegate(new MultiItemEdible(new BushToxicityDeterminent()))
|
||||
.setTranslationKey("doublePlant");
|
||||
|
||||
public static final Item tall_grass = new UItemFoodDelegate(Blocks.TALLGRASS, stack -> {
|
||||
|
@ -150,7 +152,7 @@ public class UItems {
|
|||
case 2: return "fern";
|
||||
default: return "";
|
||||
}
|
||||
}).setFoodDelegate(new ItemEdible(stack -> {
|
||||
}).setFoodDelegate(new MultiItemEdible(stack -> {
|
||||
switch (stack.getMetadata()) {
|
||||
default:
|
||||
case 0: return Toxicity.SAFE;
|
||||
|
@ -161,38 +163,38 @@ public class UItems {
|
|||
|
||||
public static final Item yellow_flower = new UItemFoodDelegate(Blocks.YELLOW_FLOWER, stack ->
|
||||
BlockFlower.EnumFlowerType.getType(BlockFlower.EnumFlowerColor.YELLOW, stack.getMetadata()).getTranslationKey()
|
||||
).setFoodDelegate(new ItemEdible(new FlowerToxicityDeterminent(BlockFlower.EnumFlowerColor.YELLOW)))
|
||||
).setFoodDelegate(new MultiItemEdible(new FlowerToxicityDeterminent(BlockFlower.EnumFlowerColor.YELLOW)))
|
||||
.setTranslationKey("flower");
|
||||
|
||||
public static final Item red_flower = new UItemFoodDelegate(Blocks.RED_FLOWER, stack ->
|
||||
BlockFlower.EnumFlowerType.getType(BlockFlower.EnumFlowerColor.RED, stack.getMetadata()).getTranslationKey()
|
||||
).setFoodDelegate(new ItemEdible(new FlowerToxicityDeterminent(BlockFlower.EnumFlowerColor.RED)))
|
||||
).setFoodDelegate(new MultiItemEdible(new FlowerToxicityDeterminent(BlockFlower.EnumFlowerColor.RED)))
|
||||
.setTranslationKey("rose");
|
||||
|
||||
public static final Item daffodil_daisy_sandwich = new ItemEdible(Unicopia.MODID, "daffodil_daisy_sandwich", 3, 2, CookedToxicityDeterminent.instance)
|
||||
public static final Item daffodil_daisy_sandwich = new MultiItemEdible(Unicopia.MODID, "daffodil_daisy_sandwich", 3, 2, CookedToxicityDeterminent.instance)
|
||||
.setHasSubtypes(true);
|
||||
public static final Item hay_burger = new ItemEdible(Unicopia.MODID, "hay_burger", 3, 4, CookedToxicityDeterminent.instance)
|
||||
public static final Item hay_burger = new MultiItemEdible(Unicopia.MODID, "hay_burger", 3, 4, CookedToxicityDeterminent.instance)
|
||||
.setHasSubtypes(true);
|
||||
public static final Item hay_fries = new ItemEdible(Unicopia.MODID, "hay_fries", 1, 5, stack -> Toxicity.SAFE);
|
||||
public static final Item salad = new ItemEdible(Unicopia.MODID, "salad", 4, 2, CookedToxicityDeterminent.instance)
|
||||
public static final Item hay_fries = new MultiItemEdible(Unicopia.MODID, "hay_fries", 1, 5, stack -> Toxicity.SAFE);
|
||||
public static final Item salad = new MultiItemEdible(Unicopia.MODID, "salad", 4, 2, CookedToxicityDeterminent.instance)
|
||||
.setHasSubtypes(true)
|
||||
.setContainerItem(Items.BOWL);
|
||||
|
||||
public static final Item wheat_worms = new ItemEdible(Unicopia.MODID, "wheat_worms", 1, 0, stack -> Toxicity.SEVERE);
|
||||
public static final Item wheat_worms = new MultiItemEdible(Unicopia.MODID, "wheat_worms", 1, 0, stack -> Toxicity.SEVERE);
|
||||
|
||||
public static final Item mug = new Item()
|
||||
.setTranslationKey("mug")
|
||||
.setRegistryName(Unicopia.MODID, "mug")
|
||||
.setCreativeTab(CreativeTabs.MATERIALS)
|
||||
.setFull3D();
|
||||
public static final Item apple_cider = new ItemEdible(Unicopia.MODID, "apple_cider", 4, 2, stack -> Toxicity.MILD)
|
||||
public static final Item apple_cider = new MultiItemEdible(Unicopia.MODID, "apple_cider", 4, 2, stack -> Toxicity.MILD)
|
||||
.setUseAction(EnumAction.DRINK)
|
||||
.setContainerItem(mug)
|
||||
.setFull3D();
|
||||
public static final Item juice = new ItemEdible(Unicopia.MODID, "juice", 2, 2, stack -> Toxicity.SAFE)
|
||||
public static final Item juice = new MultiItemEdible(Unicopia.MODID, "juice", 2, 2, stack -> Toxicity.SAFE)
|
||||
.setUseAction(EnumAction.DRINK)
|
||||
.setContainerItem(Items.GLASS_BOTTLE);
|
||||
public static final Item burned_juice = new ItemEdible(Unicopia.MODID, "burned_juice", 3, 1, stack -> Toxicity.FAIR)
|
||||
public static final Item burned_juice = new MultiItemEdible(Unicopia.MODID, "burned_juice", 3, 1, stack -> Toxicity.FAIR)
|
||||
.setUseAction(EnumAction.DRINK)
|
||||
.setContainerItem(Items.GLASS_BOTTLE);
|
||||
|
||||
|
@ -220,7 +222,7 @@ public class UItems {
|
|||
cereal, sugar_cereal, sugar_block,
|
||||
rotten_apple, zap_apple, cooked_zap_apple,
|
||||
|
||||
cloudsdale_tomato, tomato_seeds, tomato,
|
||||
cloudsdale_tomato, tomato_seeds, tomato, moss,
|
||||
|
||||
apple_seeds, apple_leaves,
|
||||
|
||||
|
@ -236,7 +238,7 @@ public class UItems {
|
|||
zap_apple,
|
||||
rotten_apple, cooked_zap_apple, dew_drop,
|
||||
|
||||
tomato, cloudsdale_tomato,
|
||||
tomato, cloudsdale_tomato, moss,
|
||||
|
||||
cloud_spawner, cloud_matter, cloud_block, enchanted_cloud, packed_cloud,
|
||||
cloud_stairs,
|
||||
|
|
121
src/main/java/com/minelittlepony/unicopia/item/ItemMoss.java
Normal file
121
src/main/java/com/minelittlepony/unicopia/item/ItemMoss.java
Normal file
|
@ -0,0 +1,121 @@
|
|||
package com.minelittlepony.unicopia.item;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.minelittlepony.unicopia.UClient;
|
||||
import com.minelittlepony.unicopia.edibles.ItemEdible;
|
||||
import com.minelittlepony.unicopia.edibles.Toxicity;
|
||||
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
|
||||
import com.minelittlepony.util.collection.ReversableStateMapList;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.block.BlockSilverfish;
|
||||
import net.minecraft.block.BlockStoneBrick;
|
||||
import net.minecraft.block.BlockWall;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
|
||||
import net.minecraft.dispenser.IBehaviorDispenseItem;
|
||||
import net.minecraft.dispenser.IBlockSource;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.IShearable;
|
||||
|
||||
public class ItemMoss extends ItemEdible {
|
||||
|
||||
public static final ReversableStateMapList affected = new ReversableStateMapList();
|
||||
|
||||
static {
|
||||
affected.replaceBlock(Blocks.MOSSY_COBBLESTONE, Blocks.COBBLESTONE);
|
||||
affected.replaceProperty(Blocks.COBBLESTONE_WALL, BlockWall.VARIANT, BlockWall.EnumType.MOSSY, BlockWall.EnumType.NORMAL);
|
||||
affected.replaceProperty(Blocks.STONEBRICK, BlockStoneBrick.VARIANT, BlockStoneBrick.EnumType.MOSSY, BlockStoneBrick.EnumType.DEFAULT);
|
||||
affected.replaceProperty(Blocks.MONSTER_EGG, BlockSilverfish.VARIANT, BlockSilverfish.EnumType.MOSSY_STONEBRICK, BlockSilverfish.EnumType.STONEBRICK);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected IBehaviorDispenseItem vanillaDispenserBehaviour;
|
||||
private final IBehaviorDispenseItem dispenserBehavior = new BehaviorDefaultDispenseItem() {
|
||||
@Override
|
||||
protected ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
|
||||
|
||||
EnumFacing facing = source.getBlockState().getValue(BlockDispenser.FACING);
|
||||
BlockPos pos = source.getBlockPos().offset(facing);
|
||||
World w = source.getWorld();
|
||||
|
||||
if (tryConvert(w, w.getBlockState(pos), pos, null)) {
|
||||
stack.attemptDamageItem(1, w.rand, null);
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
EntityPlayer player = null;
|
||||
|
||||
for (EntityLivingBase e : w.getEntitiesWithinAABB(EntityLivingBase.class, Block.FULL_BLOCK_AABB.offset(pos), e ->
|
||||
e instanceof IShearable && ((IShearable)e).isShearable(stack, w, pos)
|
||||
)) {
|
||||
if (player == null) {
|
||||
player = UClient.instance().createPlayer(e, new GameProfile(null, "Notch"));
|
||||
}
|
||||
|
||||
if (stack.interactWithEntity(player, e, EnumHand.MAIN_HAND)) {
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
||||
if (vanillaDispenserBehaviour != null) {
|
||||
return vanillaDispenserBehaviour.dispense(source, stack);
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
};
|
||||
|
||||
public ItemMoss(String domain, String name) {
|
||||
super(domain, name, 3, 0, false);
|
||||
|
||||
IBehaviorDispenseItem previous = BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.containsKey(Items.SHEARS) ? BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.getObject(Items.SHEARS) : null;
|
||||
|
||||
if (previous != null && previous != dispenserBehavior) {
|
||||
vanillaDispenserBehaviour = previous;
|
||||
}
|
||||
|
||||
BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(Items.SHEARS, dispenserBehavior);
|
||||
}
|
||||
|
||||
public boolean tryConvert(World world, IBlockState state, BlockPos pos, @Nullable EntityPlayer player) {
|
||||
IBlockState converted = affected.getConverted(state);
|
||||
|
||||
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 && PlayerSpeciesList.instance().getPlayer(player).getPlayerSpecies().canUseEarth()) {
|
||||
amount = world.rand.nextInt(4);
|
||||
}
|
||||
|
||||
Block.spawnAsEntity(world, pos, new ItemStack(this, amount));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Toxicity getToxicityLevel(ItemStack stack) {
|
||||
return Toxicity.MILD;
|
||||
}
|
||||
}
|
|
@ -63,9 +63,7 @@ public class SpellFire extends AbstractSpell.RangedAreaSpell implements IUseActi
|
|||
|
||||
affected.add(IStateMapping.build(
|
||||
s -> s.getBlock() == Blocks.DIRT && s.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT,
|
||||
s -> Math.random() <= 0.15 ?
|
||||
s.withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.COARSE_DIRT)
|
||||
: s));
|
||||
s -> (Math.random() <= 0.15 ? s.withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.COARSE_DIRT) : s)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,7 +11,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.ItemStack;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
@ -34,6 +37,22 @@ public class BlockInteractions {
|
|||
return true;
|
||||
}
|
||||
|
||||
public EnumActionResult onBlockInteract(World world, IBlockState state, BlockPos pos, EntityPlayer player, ItemStack stack, EnumHand hand) {
|
||||
|
||||
if (stack.getItem() == Items.SHEARS) {
|
||||
if (UItems.moss.tryConvert(world, state, pos, player)) {
|
||||
|
||||
if (!player.isCreative()) {
|
||||
stack.damageItem(1, player);
|
||||
}
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
|
||||
public void addAuxiliaryDrops(World world, IBlockState state, BlockPos pos, List<ItemStack> drops, int fortune) {
|
||||
Block block = state.getBlock();
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.minelittlepony.unicopia.world;
|
||||
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.entity.player.UseHoeEvent;
|
||||
import net.minecraftforge.event.terraingen.PopulateChunkEvent;
|
||||
import net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate.EventType;
|
||||
|
@ -13,6 +15,22 @@ import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
|
|||
@EventBusSubscriber
|
||||
public class Hooks {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPlayerRightClickBlock(PlayerInteractEvent.RightClickBlock event) {
|
||||
|
||||
if (event.isCanceled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
EnumActionResult result = UWorld.instance().getBlocks().onBlockInteract(
|
||||
event.getWorld(), event.getWorld().getBlockState(event.getPos()), event.getPos(), event.getEntityPlayer(), event.getItemStack(), event.getHand());
|
||||
|
||||
if (result != EnumActionResult.PASS) {
|
||||
event.setCanceled(true);
|
||||
event.setCancellationResult(result);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onBlockHarvested(BlockEvent.HarvestDropsEvent event) {
|
||||
UWorld.instance().getBlocks().addAuxiliaryDrops(event.getWorld(), event.getState(), event.getPos(), event.getDrops(), event.getFortuneLevel());
|
||||
|
|
|
@ -21,13 +21,15 @@ public interface IStateMapping extends Predicate<IBlockState>, Function<IBlockSt
|
|||
static IStateMapping replaceBlock(Block from, Block to) {
|
||||
return build(
|
||||
s -> s.getBlock() == from,
|
||||
s -> to.getDefaultState());
|
||||
s -> to.getDefaultState(),
|
||||
s -> replaceBlock(to, from));
|
||||
}
|
||||
|
||||
static <T extends Comparable<T>> IStateMapping replaceProperty(Block block, IProperty<T> property, T from, T to) {
|
||||
return build(
|
||||
s -> s.getBlock() == block && s.getValue(property) == from,
|
||||
s -> s.withProperty(property, to));
|
||||
s -> s.withProperty(property, to),
|
||||
s -> replaceProperty(block, property, to, from));
|
||||
}
|
||||
|
||||
static <T extends Comparable<T>> IStateMapping setProperty(Block block, IProperty<T> property, T to) {
|
||||
|
@ -37,7 +39,13 @@ public interface IStateMapping extends Predicate<IBlockState>, Function<IBlockSt
|
|||
}
|
||||
|
||||
static IStateMapping build(Predicate<IBlockState> predicate, Function<IBlockState, IBlockState> converter) {
|
||||
return build(predicate, converter, s -> s);
|
||||
}
|
||||
|
||||
static IStateMapping build(Predicate<IBlockState> predicate, Function<IBlockState, IBlockState> converter, Function<IStateMapping, IStateMapping> inverter) {
|
||||
return new IStateMapping() {
|
||||
private IStateMapping inverse;
|
||||
|
||||
@Override
|
||||
public boolean test(IBlockState state) {
|
||||
return predicate.test(state);
|
||||
|
@ -47,6 +55,14 @@ public interface IStateMapping extends Predicate<IBlockState>, Function<IBlockSt
|
|||
public IBlockState apply(IBlockState state) {
|
||||
return converter.apply(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStateMapping inverse() {
|
||||
if (inverse == null) {
|
||||
inverse = inverter.apply(this);
|
||||
}
|
||||
return inverse;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -74,4 +90,12 @@ public interface IStateMapping extends Predicate<IBlockState>, Function<IBlockSt
|
|||
default IBlockState apply(@Nonnull IBlockState state) {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the inverse of this mapping if one exists. Otherwise returns itself.
|
||||
*/
|
||||
@Nonnull
|
||||
default IStateMapping inverse() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.minelittlepony.util.collection;
|
||||
|
||||
public class ReversableStateMapList extends StateMapList {
|
||||
private static final long serialVersionUID = 6154365988455383098L;
|
||||
|
||||
private final StateMapList inverse = new StateMapList();
|
||||
|
||||
public StateMapList getInverse() {
|
||||
return inverse;
|
||||
}
|
||||
|
||||
public boolean add(IStateMapping mapping) {
|
||||
inverse.add(mapping.inverse());
|
||||
return super.add(mapping);
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@
|
|||
{ "item": "minecraft:golden_carrot" },
|
||||
{ "item": "minecraft:wheat" },
|
||||
{ "item": "minecraft:grain" },
|
||||
{ "item": "minecraft:alfalfa_leaves" }
|
||||
{ "item": "minecraft:alfalfa_leaves" },
|
||||
{ "item": "unicopia:moss" }
|
||||
]
|
||||
}
|
|
@ -5,6 +5,7 @@
|
|||
{ "item": "unicopia:tomato", "data": 1 },
|
||||
{ "item": "unicopia:rotten_apple" },
|
||||
{ "item": "minecraft:red_mushroom" },
|
||||
{ "item": "minecraft:brown_mushroom" }
|
||||
{ "item": "minecraft:brown_mushroom" },
|
||||
{ "item": "unicopia:moss" }
|
||||
]
|
||||
}
|
|
@ -30,6 +30,7 @@ item.mist_door.name=Cloud Door
|
|||
item.dew_drop.name=Dew Drop
|
||||
item.cloud_anvil.name=Anvilhead Anvil
|
||||
|
||||
item.moss.name=Moss
|
||||
item.staff_meadow_brook.name=Meadow Brook's Staff
|
||||
item.staff_meadow_brook.tagline=It's a big stick
|
||||
item.alicorn_amulet.name=The Alicorn Amulet
|
||||
|
|
6
src/main/resources/assets/unicopia/models/item/moss.json
Normal file
6
src/main/resources/assets/unicopia/models/item/moss.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "unicopia:items/moss"
|
||||
}
|
||||
}
|
BIN
src/main/resources/assets/unicopia/textures/items/moss.png
Normal file
BIN
src/main/resources/assets/unicopia/textures/items/moss.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3 KiB |
Loading…
Reference in a new issue