Porting to Fabric/Yarn/1.14 part 4

This commit is contained in:
Sollace 2020-01-27 12:05:22 +02:00
parent 9a42c8ebd5
commit 11de4c8821
142 changed files with 3230 additions and 4004 deletions

View file

@ -0,0 +1,98 @@
package com.minelittlepony.unicopia;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectType;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
public class CustomStatusEffect extends StatusEffect {
private int tickDelay = 40;
@Nonnull
private DirectEffect direct = DirectEffect.NONE;
@Nonnull
private IndirectEffect indirect = IndirectEffect.NONE;
public CustomStatusEffect(Identifier id, StatusEffectType type, int color) {
super(type, color);
Registry.register(Registry.STATUS_EFFECT, id, this);
}
public CustomStatusEffect setSilent() {
return this;
}
public CustomStatusEffect direct(@Nonnull DirectEffect applicator) {
this.direct = applicator;
return this;
}
public CustomStatusEffect indirect(@Nonnull IndirectEffect applicator) {
this.indirect = applicator;
return this;
}
public CustomStatusEffect setTickDelay(int delay) {
tickDelay = delay;
return this;
}
public CustomStatusEffect setEffectiveness(double effectiveness) {
return this;
}
@Override
public void applyUpdateEffect(LivingEntity target, int amplifier) {
direct.perform(this, target, amplifier);
}
@Override
public void applyInstantEffect(@Nullable Entity source, @Nullable Entity attacker, LivingEntity target, int amplifier, double distance) {
indirect.perform(this, source, attacker, target, amplifier, distance);
}
@Override
public boolean isInstant() {
return tickDelay > 0;
}
@Override
public boolean canApplyUpdateEffect(int duration, int amplifier) {
if (!isInstant()) {
int i = tickDelay >> amplifier;
if (i > 0) {
return duration % i == 0;
}
}
return duration > 0;
}
@FunctionalInterface
public interface DirectEffect {
DirectEffect NONE = (p, e, i) -> {};
void perform(StatusEffect effect, LivingEntity target, int amplifier);
}
@FunctionalInterface
public interface IndirectEffect {
IndirectEffect NONE = (p, s, a, t, A, d) -> {};
void perform(StatusEffect effect, @Nullable Entity source, @Nullable Entity attacker, LivingEntity target, int amplifier, double distance);
}
}

View file

@ -0,0 +1,51 @@
package com.minelittlepony.unicopia;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.client.ClientInteractionManager;
import com.minelittlepony.unicopia.entity.capabilities.IPlayer;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
public interface InteractionManager {
static InteractionManager instance() {
if (Unicopia.interactionManager == null) {
if (ServerInteractionManager.isClientSide()) {
Unicopia.interactionManager = new ClientInteractionManager();
} else {
Unicopia.interactionManager = new ServerInteractionManager();
}
}
return Unicopia.interactionManager;
}
@Nullable
PlayerEntity getClientPlayer();
@Nullable
default IPlayer getIPlayer() {
return SpeciesList.instance().getPlayer(getClientPlayer());
}
boolean isClientPlayer(@Nullable PlayerEntity player);
int getViewMode();
/**
* Side-independent method to create a new player.
*
* Returns an implementation of PlayerEntity appropriate to the side being called on.
*/
@Nonnull
PlayerEntity createPlayer(Entity observer, GameProfile profile);
void postRenderEntity(Entity entity);
boolean renderEntity(Entity entity, float renderPartialTicks);
}

View file

@ -34,6 +34,10 @@ public enum Race {
this.earth = earth; this.earth = earth;
} }
public boolean isUsable() {
return !isDefault();
}
public boolean isDefault() { public boolean isDefault() {
return this == HUMAN; return this == HUMAN;
} }

View file

@ -0,0 +1,61 @@
package com.minelittlepony.unicopia;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.minelittlepony.util.dummy.DummyPlayerEntity;
import com.minelittlepony.util.dummy.DummyServerPlayerEntity;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.world.ServerWorld;
public class ServerInteractionManager implements InteractionManager {
@Deprecated
public static boolean isClientSide() {
return false;
}
@Override
@Nullable
public PlayerEntity getClientPlayer() {
return null;
}
@Override
public boolean isClientPlayer(@Nullable PlayerEntity player) {
return false;
}
@Override
public int getViewMode() {
return 0;
}
/**
* Side-independent method to create a new player.
*
* Returns an implementation of PlayerEntity appropriate to the side being called on.
*/
@Override
@Nonnull
public PlayerEntity createPlayer(Entity observer, GameProfile profile) {
if (observer.world instanceof ServerWorld) {
return new DummyServerPlayerEntity((ServerWorld)observer.world, profile);
}
return new DummyPlayerEntity(observer.world, profile);
}
@Override
public void postRenderEntity(Entity entity) {
}
@Override
public boolean renderEntity(Entity entity, float renderPartialTicks) {
return false;
}
}

View file

@ -1,8 +1,6 @@
package com.minelittlepony.unicopia; package com.minelittlepony.unicopia;
import java.util.Optional; import java.util.Optional;
import java.util.UUID;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.minelittlepony.unicopia.Config; import com.minelittlepony.unicopia.Config;
@ -62,11 +60,6 @@ public class SpeciesList {
return this.<IPlayer>getEntity(player); return this.<IPlayer>getEntity(player);
} }
@Nullable
public IPlayer getPlayer(UUID playerId) {
return getPlayer(IPlayer.fromServer(playerId));
}
@Nullable @Nullable
public <T extends IEntity> T getEntity(Entity entity) { public <T extends IEntity> T getEntity(Entity entity) {
return this.<Entity, T>getForEntity(entity) return this.<Entity, T>getForEntity(entity)

View file

@ -14,67 +14,67 @@ import com.minelittlepony.unicopia.block.HiveWallBlock;
import com.minelittlepony.unicopia.block.IColourful; import com.minelittlepony.unicopia.block.IColourful;
import com.minelittlepony.unicopia.block.SlimeLayerBlock; import com.minelittlepony.unicopia.block.SlimeLayerBlock;
import com.minelittlepony.unicopia.block.StickBlock; import com.minelittlepony.unicopia.block.StickBlock;
import com.minelittlepony.unicopia.block.BlockCloudAnvil; import com.minelittlepony.unicopia.block.CloudAnvilBlock;
import com.minelittlepony.unicopia.block.BlockCloudBanister; import com.minelittlepony.unicopia.block.CloudSlabBlock;
import com.minelittlepony.unicopia.block.BlockCloudSlab; import com.minelittlepony.unicopia.block.CloudBanisterBlock;
import com.minelittlepony.unicopia.block.BlockCloudStairs; import com.minelittlepony.unicopia.block.BlockCloudStairs;
import com.minelittlepony.unicopia.block.BlockDutchDoor; import com.minelittlepony.unicopia.block.DutchDoorBlock;
import com.minelittlepony.unicopia.block.SugarBlock; import com.minelittlepony.unicopia.block.SugarBlock;
import com.minelittlepony.unicopia.block.UPot; import com.minelittlepony.unicopia.block.UPot;
import com.minelittlepony.unicopia.block.USapling; import com.minelittlepony.unicopia.item.AppleItem;
import com.minelittlepony.unicopia.world.structure.CustomSaplingGenerator;
import com.minelittlepony.unicopia.block.BlockTomatoPlant; import com.minelittlepony.unicopia.block.BlockTomatoPlant;
import com.minelittlepony.unicopia.block.BlockCloudDoor; import com.minelittlepony.unicopia.block.BlockCloudDoor;
import com.minelittlepony.unicopia.block.BlockDiamondDoor; import com.minelittlepony.unicopia.block.DiamondDoorBlock;
import com.minelittlepony.unicopia.block.BlockCloudFarm; import com.minelittlepony.unicopia.block.BlockCloudFarm;
import com.minelittlepony.unicopia.block.BlockCloudFence; import com.minelittlepony.unicopia.block.CloudFenceBlock;
import com.minelittlepony.unicopia.block.BlockCloud; import com.minelittlepony.unicopia.block.CloudBlock;
import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.minecraft.block.Block; 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.block.Material; import net.minecraft.block.Material;
import net.minecraft.block.SaplingBlock;
import net.minecraft.client.color.block.BlockColors; import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.color.item.ItemColors; import net.minecraft.client.color.item.ItemColors;
import net.minecraft.client.color.world.BiomeColors; import net.minecraft.client.color.world.BiomeColors;
import net.minecraft.client.color.world.GrassColors; import net.minecraft.client.color.world.GrassColors;
import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
public class UBlocks { public class UBlocks {
public static final BlockCloud normal_cloud = register(new BlockCloud(UMaterials.cloud, CloudType.NORMAL), "cloud_block"); public static final CloudBlock normal_cloud = register(new CloudBlock(UMaterials.cloud, CloudType.NORMAL), "cloud_block");
public static final BlockCloud enchanted_cloud = register(new BlockCloud(UMaterials.cloud, CloudType.ENCHANTED), "enchanted_cloud_block"); public static final CloudBlock enchanted_cloud = register(new CloudBlock(UMaterials.cloud, CloudType.ENCHANTED), "enchanted_cloud_block");
public static final BlockCloud packed_cloud = register(new BlockCloud(UMaterials.cloud, CloudType.PACKED), "packed_cloud_block"); public static final CloudBlock packed_cloud = register(new CloudBlock(UMaterials.cloud, CloudType.PACKED), "packed_cloud_block");
public static final BlockCloudStairs cloud_stairs = register(new BlockCloudStairs(normal_cloud.getDefaultState(), Unicopia.MODID, "cloud_stairs")); public static final BlockCloudStairs cloud_stairs = register(new BlockCloudStairs(normal_cloud.getDefaultState()), "cloud_stairs");
public static final BlockCloudSlab.Single<?> cloud_slab = register(new BlockCloudSlab.Single<>(normal_cloud, UMaterials.cloud, Unicopia.MODID, "cloud_slab")); public static final CloudSlabBlock<CloudBlock> cloud_slab = register(new CloudSlabBlock<>(normal_cloud, UMaterials.cloud), "cloud_slab");
public static final BlockCloudSlab.Single<?> enchanted_cloud_slab = register(new BlockCloudSlab.Single<>(enchanted_cloud, UMaterials.cloud, Unicopia.MODID, "enchanted_cloud_slab")); public static final CloudSlabBlock<CloudBlock> enchanted_cloud_slab = register(new CloudSlabBlock<>(enchanted_cloud, UMaterials.cloud), "enchanted_cloud_slab");
public static final BlockCloudSlab.Single<?> packed_cloud_slab = register(new BlockCloudSlab.Single<>(enchanted_cloud, UMaterials.cloud, Unicopia.MODID, "packed_cloud_slab")); public static final CloudSlabBlock<CloudBlock> packed_cloud_slab = register(new CloudSlabBlock<>(enchanted_cloud, UMaterials.cloud), "packed_cloud_slab");
public static final BlockCloudDoor mist_door = register(new BlockCloudDoor(UMaterials.cloud, Unicopia.MODID, "mist_door", () -> UItems.mist_door)); public static final BlockCloudDoor mist_door = register(new BlockCloudDoor(), "mist_door");
public static final Block library_door = register(new BlockDutchDoor(Material.WOOD, Unicopia.MODID, "library_door", () -> UItems.library_door) public static final DutchDoorBlock library_door = register(new DutchDoorBlock(FabricBlockSettings.of(Material.WOOD).sounds(BlockSoundGroup.WOOD).hardness(3).build()), "library_door");
.setSoundType(SoundType.WOOD) public static final DutchDoorBlock bakery_door = register(new DutchDoorBlock(FabricBlockSettings.of(Material.WOOD).sounds(BlockSoundGroup.WOOD).hardness(3).build()), "bakery_door");
.setHardness(3)); public static final DiamondDoorBlock diamond_door = register(new DiamondDoorBlock(), "diamond_door");
public static final Block bakery_door = register(new BlockDutchDoor(Material.WOOD, Unicopia.MODID, "bakery_door", () -> UItems.bakery_door)
.setSoundType(SoundType.WOOD)
.setHardness(3));
public static final Block diamond_door = register(new BlockDiamondDoor(Unicopia.MODID, "diamond_door", () -> UItems.diamond_door));
public static final GlowingGemBlock enchanted_torch = register(new GlowingGemBlock(Unicopia.MODID, "enchanted_torch")); public static final GlowingGemBlock enchanted_torch = register(new GlowingGemBlock(), "enchanted_torch");
public static final BlockCloudAnvil anvil = register(new BlockCloudAnvil(Unicopia.MODID, "anvil")); public static final CloudAnvilBlock anvil = register(new CloudAnvilBlock(), "anvil");
public static final BlockCloudFence cloud_fence = register(new BlockCloudFence(UMaterials.cloud, CloudType.NORMAL, Unicopia.MODID, "cloud_fence")); public static final CloudFenceBlock cloud_fence = register(new CloudFenceBlock(UMaterials.cloud, CloudType.NORMAL), "cloud_fence");
public static final BlockCloudBanister cloud_banister = register(new BlockCloudBanister(UMaterials.cloud, Unicopia.MODID, "cloud_banister")); public static final CloudBanisterBlock cloud_banister = register(new CloudBanisterBlock(UMaterials.cloud), "cloud_banister");
public static final BlockAlfalfa alfalfa = register(new BlockAlfalfa(Unicopia.MODID, "alfalfa")); public static final BlockAlfalfa alfalfa = register(new BlockAlfalfa(), "alfalfa");
public static final StickBlock stick = register(new StickBlock(), "stick"); public static final StickBlock stick = register(new StickBlock(), "stick");
public static final BlockTomatoPlant tomato_plant = register(new BlockTomatoPlant(Unicopia.MODID, "tomato_plant")); public static final BlockTomatoPlant tomato_plant = register(new BlockTomatoPlant(), "tomato_plant");
public static final BlockCloudFarm cloud_farmland = register(new BlockCloudFarm(Unicopia.MODID, "cloud_farmland")); public static final BlockCloudFarm cloud_farmland = register(new BlockCloudFarm(), "cloud_farmland");
public static final HiveWallBlock hive = register(new HiveWallBlock(), "hive"); public static final HiveWallBlock hive = register(new HiveWallBlock(), "hive");
public static final ChitinBlock chitin = register(new ChitinBlock(), "chitin_block"); public static final ChitinBlock chitin = register(new ChitinBlock(), "chitin_block");
@ -86,8 +86,10 @@ public class UBlocks {
public static final Block sugar_block = register(new SugarBlock(), "sugar_block"); public static final Block sugar_block = register(new SugarBlock(), "sugar_block");
public static final UPot flower_pot = register(new UPot(), "flower_pot"); public static final UPot flower_pot = register(new UPot(), "flower_pot");
public static final USapling apple_tree = register(new USapling(Unicopia.MODID, "apple_sapling") public static final SaplingBlock apple_tree = register(new SaplingBlock(
.setTreeGen((w, s, m) -> new WorldGenTrees(true, 5, Blocks.LOG.getDefaultState(), UBlocks.apple_leaves.getDefaultState(), false)); new CustomSaplingGenerator(5, Blocks.OAK_LOG.getDefaultState(), UBlocks.apple_leaves.getDefaultState()),
FabricBlockSettings.of(Material.WOOD).build()
) {}, "apple_sapling");
public static final Block apple_leaves = register(new FruitLeavesBlock() public static final Block apple_leaves = register(new FruitLeavesBlock()
.growthChance(1200) .growthChance(1200)
.tint(0xFFEE81) .tint(0xFFEE81)

View file

@ -1,88 +0,0 @@
package com.minelittlepony.unicopia;
import java.util.UUID;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.client.UnicopiaClient;
import com.minelittlepony.unicopia.entity.EntityFakeServerPlayer;
import com.minelittlepony.unicopia.entity.capabilities.IPlayer;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
public class UClient {
private static UClient instance;
public static boolean isClientSide() {
return false;
}
public static UClient instance() {
if (instance == null) {
if (isClientSide()) {
instance = new UnicopiaClient();
} else {
instance = new UClient();
}
}
return instance;
}
public void displayGuiToPlayer(PlayerEntity player, InteractionObject inventory) {
player.displayGui(inventory);
}
@Nullable
public PlayerEntity getPlayer() {
return null;
}
@Nullable
public IPlayer getIPlayer() {
return SpeciesList.instance().getPlayer(getPlayer());
}
@Nullable
public PlayerEntity getPlayerByUUID(UUID playerId) {
return null;
}
public boolean isClientPlayer(@Nullable PlayerEntity player) {
return false;
}
public int getViewMode() {
return 0;
}
/**
* Side-independent method to create a new player.
*
* Returns an implementation of PlayerEntity appropriate to the side being called on.
*/
@Nonnull
public PlayerEntity createPlayer(Entity observer, GameProfile profile) {
return new EntityFakeServerPlayer((WorldServer)observer.world, profile);
}
public void postRenderEntity(Entity entity) {
}
public boolean renderEntity(Entity entity, float renderPartialTicks) {
return false;
}
public void tick() {}
public void preInit() {}
public void init() {}
public void postInit() {}
}

View file

@ -0,0 +1,15 @@
package com.minelittlepony.unicopia;
import com.minelittlepony.unicopia.inventory.gui.ContainerOfHolding;
import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
import net.minecraft.util.Identifier;
public class UContainers {
public static final Identifier BAG_OF_HOLDING = new Identifier(Unicopia.MODID, "bag_of_holding");
static void bootstrap() {
ContainerProviderRegistry.INSTANCE.registerFactory(BAG_OF_HOLDING, ContainerOfHolding::new);
}
}

View file

@ -3,24 +3,21 @@ package com.minelittlepony.unicopia;
import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.util.MagicalDamageSource; import com.minelittlepony.util.MagicalDamageSource;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffectType;
import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.potion.Potion; import net.minecraft.util.Identifier;
public class UEffects { public class UEffects {
public static final StatusEffect FOOD_POISONING = new UPotion(Unicopia.MODID, "food_poisoning", true, 3484199) public static final StatusEffect FOOD_POISONING = new CustomStatusEffect(new Identifier(Unicopia.MODID, "food_poisoning"), StatusEffectType.BENEFICIAL, 3484199)
.setIconIndex(3, 1)
.setSilent() .setSilent()
.setEffectiveness(0.25) .direct((p, e, i) -> {
.setApplicator((p, e, i) -> {
StatusEffectInstance nausea = e.getStatusEffect(StatusEffects.NAUSEA); StatusEffectInstance nausea = e.getStatusEffect(StatusEffects.NAUSEA);
if (nausea == null) { if (nausea == null) {
StatusEffectInstance foodEffect = e.getStatusEffect(p); StatusEffectInstance foodEffect = e.getStatusEffect(p);
nausea = new StatusEffectInstance(StatusEffects.NAUSEA, foodEffect.getDuration(), foodEffect.getAmplifier(), foodEffect.getIsAmbient(), foodEffect.doesShowParticles()); nausea = new StatusEffectInstance(StatusEffects.NAUSEA, foodEffect.getDuration(), foodEffect.getAmplifier(), foodEffect.isAmbient(), foodEffect.shouldShowParticles());
e.addPotionEffect(nausea); e.addPotionEffect(nausea);
} }

View file

@ -2,12 +2,12 @@ package com.minelittlepony.unicopia;
import com.minelittlepony.unicopia.entity.ButterflyEntity; import com.minelittlepony.unicopia.entity.ButterflyEntity;
import com.minelittlepony.unicopia.entity.CloudEntity; import com.minelittlepony.unicopia.entity.CloudEntity;
import com.minelittlepony.unicopia.entity.AdvancedProjectileEntity; import com.minelittlepony.unicopia.entity.ProjectileEntity;
import com.minelittlepony.unicopia.entity.ConstructionCloudEntity; import com.minelittlepony.unicopia.entity.ConstructionCloudEntity;
import com.minelittlepony.unicopia.entity.EntityCuccoon; import com.minelittlepony.unicopia.entity.CuccoonEntity;
import com.minelittlepony.unicopia.entity.EntityRacingCloud; import com.minelittlepony.unicopia.entity.RacingCloudEntity;
import com.minelittlepony.unicopia.entity.RainbowEntity; import com.minelittlepony.unicopia.entity.RainbowEntity;
import com.minelittlepony.unicopia.entity.EntitySpear; import com.minelittlepony.unicopia.entity.SpearEntity;
import com.minelittlepony.unicopia.entity.SpellcastEntity; import com.minelittlepony.unicopia.entity.SpellcastEntity;
import com.minelittlepony.util.collection.ListHelper; import com.minelittlepony.util.collection.ListHelper;
import com.minelittlepony.unicopia.entity.SpellbookEntity; import com.minelittlepony.unicopia.entity.SpellbookEntity;
@ -30,23 +30,23 @@ public class UEntities {
public static final EntityType<SpellcastEntity> MAGIC_SPELL = register("magic_spell", EntityType.Builder.create(SpellcastEntity::new, EntityCategory.MISC).setDimensions(0.6F, 0.25F)); public static final EntityType<SpellcastEntity> MAGIC_SPELL = register("magic_spell", EntityType.Builder.create(SpellcastEntity::new, EntityCategory.MISC).setDimensions(0.6F, 0.25F));
public static final EntityType<CloudEntity> CLOUD = register("cloud", EntityType.Builder.create(CloudEntity::new, EntityCategory.CREATURE)); public static final EntityType<CloudEntity> CLOUD = register("cloud", EntityType.Builder.create(CloudEntity::new, EntityCategory.CREATURE));
public static final EntityType<WildCloudEntity> WILD_CLOUD = register("wild_cloud", EntityType.Builder.create(WildCloudEntity::new, EntityCategory.CREATURE)); public static final EntityType<WildCloudEntity> WILD_CLOUD = register("wild_cloud", EntityType.Builder.create(WildCloudEntity::new, EntityCategory.CREATURE));
public static final EntityType<EntityRacingCloud> RACING_CLOUD = register("racing_cloud", EntityType.Builder.create(EntityRacingCloud::new, EntityCategory.CREATURE)); public static final EntityType<RacingCloudEntity> RACING_CLOUD = register("racing_cloud", EntityType.Builder.create(RacingCloudEntity::new, EntityCategory.CREATURE));
public static final EntityType<ConstructionCloudEntity> CONSTRUCTION_CLOUD = register("construction_cloud", EntityType.Builder.create(ConstructionCloudEntity::new, EntityCategory.CREATURE)); public static final EntityType<ConstructionCloudEntity> CONSTRUCTION_CLOUD = register("construction_cloud", EntityType.Builder.create(ConstructionCloudEntity::new, EntityCategory.CREATURE));
public static final EntityType<RainbowEntity> RAINBOW = register("rainbow", EntityType.Builder.create(RainbowEntity::new, EntityCategory.AMBIENT)); public static final EntityType<RainbowEntity> RAINBOW = register("rainbow", EntityType.Builder.create(RainbowEntity::new, EntityCategory.AMBIENT));
public static final EntityType<RainbowEntity.Spawner> RAINBOW_SPAWNER = register("rainbow_spawner", EntityType.Builder.create(RainbowEntity.Spawner::new, EntityCategory.MISC)); public static final EntityType<RainbowEntity.Spawner> RAINBOW_SPAWNER = register("rainbow_spawner", EntityType.Builder.create(RainbowEntity.Spawner::new, EntityCategory.MISC));
public static final EntityType<EntityCuccoon> CUCCOON = register("cuccoon", EntityType.Builder.create(EntityCuccoon::new, EntityCategory.MISC).setDimensions(0.6f, 0.6f)); public static final EntityType<CuccoonEntity> CUCCOON = register("cuccoon", EntityType.Builder.create(CuccoonEntity::new, EntityCategory.MISC).setDimensions(1.5F, 1.6F));
public static final EntityType<ButterflyEntity> BUTTERFLY = register("butterfly", EntityType.Builder.create(ButterflyEntity::new, EntityCategory.AMBIENT)); public static final EntityType<ButterflyEntity> BUTTERFLY = register("butterfly", EntityType.Builder.create(ButterflyEntity::new, EntityCategory.AMBIENT));
public static final EntityType<AdvancedProjectileEntity> THROWN_ITEM = register("thrown_item", EntityType.Builder.create(AdvancedProjectileEntity::new, EntityCategory.MISC)); public static final EntityType<ProjectileEntity> THROWN_ITEM = register("thrown_item", EntityType.Builder.create(ProjectileEntity::new, EntityCategory.MISC));
public static final EntityType<EntitySpear> THROWN_SPEAR = register("thrown_spear", EntityType.Builder.create(EntitySpear::new, EntityCategory.MISC)); public static final EntityType<SpearEntity> THROWN_SPEAR = register("thrown_spear", EntityType.Builder.create(SpearEntity::new, EntityCategory.MISC));
//builder.creature(CloudEntity.class, "cloud").withEgg(0x4169e1, 0x7fff00), //builder.creature(CloudEntity.class, "cloud").withEgg(0x4169e1, 0x7fff00),
//builder.creature(ButterflyEntity.class, "butterfly").withEgg(0x222200, 0xaaeeff), //builder.creature(ButterflyEntity.class, "butterfly").withEgg(0x222200, 0xaaeeff),
// builder.projectile(AdvancedProjectileEntity.class, "thrown_item", 100, 10), // builder.projectile(ProjectileEntity.class, "thrown_item", 100, 10),
// builder.projectile(EntitySpear.class, "spear", 100, 10) // builder.projectile(SpearEntity.class, "spear", 100, 10)
private static <T extends Entity> EntityType<T> register(String name, EntityType.Builder<T> builder) { private static <T extends Entity> EntityType<T> register(String name, EntityType.Builder<T> builder) {
return Registry.register(Registry.ENTITY_TYPE, name, builder.build(name)); return Registry.register(Registry.ENTITY_TYPE, name, builder.build(name));

View file

@ -1,34 +1,34 @@
package com.minelittlepony.unicopia; package com.minelittlepony.unicopia;
import com.minelittlepony.unicopia.item.ItemAlicornAmulet; import com.minelittlepony.unicopia.item.AlicornAmuletItem;
import com.minelittlepony.unicopia.item.ItemAppleMultiType; import com.minelittlepony.unicopia.item.SugaryItem;
import com.minelittlepony.unicopia.item.ItemCereal;
import com.minelittlepony.unicopia.item.AppleItem; import com.minelittlepony.unicopia.item.AppleItem;
import com.minelittlepony.unicopia.item.CloudPlacerItem; import com.minelittlepony.unicopia.item.CloudPlacerItem;
import com.minelittlepony.unicopia.item.ExtendedShearsItem; import com.minelittlepony.unicopia.item.ExtendedShearsItem;
import com.minelittlepony.unicopia.item.CursedMagicGemItem; import com.minelittlepony.unicopia.item.CursedMagicGemItem;
import com.minelittlepony.unicopia.item.ItemMagicStaff; import com.minelittlepony.unicopia.item.EnchantedStaffItem;
import com.minelittlepony.unicopia.item.MossItem; import com.minelittlepony.unicopia.item.MossItem;
import com.minelittlepony.unicopia.item.ItemOfHolding; import com.minelittlepony.unicopia.item.BagOfHoldingItem;
import com.minelittlepony.unicopia.item.RottenAppleItem; import com.minelittlepony.unicopia.item.RottenAppleItem;
import com.minelittlepony.unicopia.item.RottenTomatoItem; import com.minelittlepony.unicopia.item.RottenTomatoItem;
import com.minelittlepony.unicopia.item.ItemSpear; import com.minelittlepony.unicopia.item.SpearItem;
import com.minelittlepony.unicopia.item.MagicGemItem; import com.minelittlepony.unicopia.item.MagicGemItem;
import com.minelittlepony.unicopia.item.SpellbookItem; import com.minelittlepony.unicopia.item.SpellbookItem;
import com.minelittlepony.unicopia.item.ItemStaff; import com.minelittlepony.unicopia.item.StaffItem;
import com.minelittlepony.unicopia.item.TomatoItem; import com.minelittlepony.unicopia.item.TomatoItem;
import com.minelittlepony.unicopia.item.TomatoSeedsItem; import com.minelittlepony.unicopia.item.TomatoSeedsItem;
import com.minelittlepony.unicopia.item.ItemZapApple; import com.minelittlepony.unicopia.item.ZapAppleItem;
import com.minelittlepony.unicopia.item.PredicatedBlockItem; import com.minelittlepony.unicopia.item.PredicatedBlockItem;
import com.minelittlepony.unicopia.item.StickItem; import com.minelittlepony.unicopia.item.StickItem;
import com.minelittlepony.unicopia.item.URecord; import com.minelittlepony.unicopia.item.URecord;
import com.minelittlepony.unicopia.item.consumables.BushToxicityDeterminent; import com.minelittlepony.unicopia.item.consumables.BushToxicityDeterminent;
import com.minelittlepony.unicopia.item.consumables.CookedToxicityDeterminent; import com.minelittlepony.unicopia.item.consumables.CookedToxicityDeterminent;
import com.minelittlepony.unicopia.item.consumables.FlowerToxicityDeterminent; import com.minelittlepony.unicopia.item.consumables.FlowerToxicityDeterminent;
import com.minelittlepony.unicopia.item.consumables.MultiItemEdible; import com.minelittlepony.unicopia.item.consumables.DelegatedEdibleItem;
import com.minelittlepony.unicopia.item.consumables.Toxicity; import com.minelittlepony.unicopia.item.consumables.Toxicity;
import com.minelittlepony.unicopia.item.consumables.UItemFoodDelegate; import com.minelittlepony.unicopia.item.consumables.DelegateFoodItem;
import com.minelittlepony.unicopia.magic.spells.SpellRegistry; import com.minelittlepony.unicopia.magic.spells.SpellRegistry;
import com.minelittlepony.unicopia.magic.spells.SpellScorch;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemGroup;
@ -37,6 +37,7 @@ import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.color.item.ItemColors; import net.minecraft.client.color.item.ItemColors;
import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItem;
import net.minecraft.item.FoodComponent;
import net.minecraft.item.FoodComponents; import net.minecraft.item.FoodComponents;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
@ -50,10 +51,10 @@ import static com.minelittlepony.unicopia.EquinePredicates.*;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.minelittlepony.unicopia.UClient; import com.minelittlepony.unicopia.ServerInteractionManager;
import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.entity.ConstructionCloudEntity; import com.minelittlepony.unicopia.entity.ConstructionCloudEntity;
import com.minelittlepony.unicopia.entity.EntityRacingCloud; import com.minelittlepony.unicopia.entity.RacingCloudEntity;
import com.minelittlepony.unicopia.entity.WildCloudEntity; import com.minelittlepony.unicopia.entity.WildCloudEntity;
import com.minelittlepony.unicopia.forgebullshit.BuildInTexturesBakery; import com.minelittlepony.unicopia.forgebullshit.BuildInTexturesBakery;
import com.minelittlepony.unicopia.forgebullshit.OreReplacer; import com.minelittlepony.unicopia.forgebullshit.OreReplacer;
@ -69,7 +70,7 @@ public class UItems {
public static final AppleItem sweet_apple = register(new AppleItem(FoodComponents.APPLE), "apple_sweet"); public static final AppleItem sweet_apple = register(new AppleItem(FoodComponents.APPLE), "apple_sweet");
public static final AppleItem sour_apple = register(new AppleItem(FoodComponents.APPLE), "apple_sour"); public static final AppleItem sour_apple = register(new AppleItem(FoodComponents.APPLE), "apple_sour");
public static final ItemAppleMultiType zap_apple = new ItemZapApple(Unicopia.MODID, "zap_apple").setSubTypes("zap_apple", "red", "green", "sweet", "sour", "zap"); public static final ZapAppleItem zap_apple = register(new ZapAppleItem(), "zap_apple");
public static final AppleItem rotten_apple = register(new RottenAppleItem(FoodComponents.APPLE), "rotten_apple"); public static final AppleItem rotten_apple = register(new RottenAppleItem(FoodComponents.APPLE), "rotten_apple");
public static final AppleItem cooked_zap_apple = register(new AppleItem(FoodComponents.APPLE), "cooked_zap_apple"); public static final AppleItem cooked_zap_apple = register(new AppleItem(FoodComponents.APPLE), "cooked_zap_apple");
@ -77,9 +78,9 @@ public class UItems {
public static final Item cloud_matter = register(new Item(new Item.Settings().group(ItemGroup.MATERIALS)), "cloud_matter"); public static final Item cloud_matter = register(new Item(new Item.Settings().group(ItemGroup.MATERIALS)), "cloud_matter");
public static final Item dew_drop = register(new Item(new Item.Settings().group(ItemGroup.MATERIALS)), "dew_drop"); public static final Item dew_drop = register(new Item(new Item.Settings().group(ItemGroup.MATERIALS)), "dew_drop");
public static final CloudPlacerItem racing_cloud_spawner = register(new CloudPlacerItem(EntityRacingCloud::new), "racing_cloud_spawner"); public static final CloudPlacerItem racing_cloud_spawner = register(new CloudPlacerItem(UEntities.RACING_CLOUD), "racing_cloud_spawner");
public static final CloudPlacerItem construction_cloud_spawner = register(new CloudPlacerItem(ConstructionCloudEntity::new), "construction_cloud_spawner"); public static final CloudPlacerItem construction_cloud_spawner = register(new CloudPlacerItem(UEntities.CONSTRUCTION_CLOUD), "construction_cloud_spawner");
public static final CloudPlacerItem wild_cloud_spawner = register(new CloudPlacerItem(WildCloudEntity::new), "wild_cloud_spawner"); public static final CloudPlacerItem wild_cloud_spawner = register(new CloudPlacerItem(UEntities.WILD_CLOUD), "wild_cloud_spawner");
public static final Item cloud_block = register(new PredicatedBlockItem(UBlocks.normal_cloud, new Item.Settings().group(ItemGroup.MATERIALS), INTERACT_WITH_CLOUDS), "cloud_block"); public static final Item cloud_block = register(new PredicatedBlockItem(UBlocks.normal_cloud, new Item.Settings().group(ItemGroup.MATERIALS), INTERACT_WITH_CLOUDS), "cloud_block");
public static final Item enchanted_cloud = register(new PredicatedBlockItem(UBlocks.enchanted_cloud, new Item.Settings().group(ItemGroup.MATERIALS), INTERACT_WITH_CLOUDS), "enchanted_cloud_block"); public static final Item enchanted_cloud = register(new PredicatedBlockItem(UBlocks.enchanted_cloud, new Item.Settings().group(ItemGroup.MATERIALS), INTERACT_WITH_CLOUDS), "enchanted_cloud_block");
@ -118,36 +119,53 @@ public class UItems {
public static final MagicGemItem spell = register(new MagicGemItem(), "gem"); public static final MagicGemItem spell = register(new MagicGemItem(), "gem");
public static final MagicGemItem curse = register(new CursedMagicGemItem(), "corrupted_gem"); public static final MagicGemItem curse = register(new CursedMagicGemItem(), "corrupted_gem");
public static final ItemOfHolding bag_of_holding = new ItemOfHolding(Unicopia.MODID, "bag_of_holding"); public static final BagOfHoldingItem bag_of_holding = register(new BagOfHoldingItem(), "bag_of_holding");
public static final ItemAlicornAmulet alicorn_amulet = new ItemAlicornAmulet(Unicopia.MODID, "alicorn_amulet"); public static final AlicornAmuletItem alicorn_amulet = register(new AlicornAmuletItem(), "alicorn_amulet");
public static final SpellbookItem spellbook = register(new SpellbookItem(), "spellbook"); public static final SpellbookItem spellbook = register(new SpellbookItem(), "spellbook");
public static final Item staff_meadow_brook = new ItemStaff(Unicopia.MODID, "staff_meadow_brook").setMaxDamage(2); public static final Item staff_meadow_brook = register(new StaffItem(new Item.Settings().maxCount(1).maxDamage(2)), "staff_meadow_brook");
public static final Item staff_remembrance = new ItemMagicStaff(Unicopia.MODID, "staff_remembrance", new SpellScorch()); public static final Item staff_remembrance = register(new EnchantedStaffItem(new Item.Settings(), new SpellScorch()), "staff_remembrance");
public static final Item spear = new ItemSpear(Unicopia.MODID, "spear"); public static final Item spear = register(new SpearItem(new Item.Settings().maxCount(1).maxDamage(500)), "spear");
public static final MossItem moss = new MossItem(Unicopia.MODID, "moss"); public static final MossItem moss = register(new MossItem(new Item.Settings()), "moss");
public static final Item alfalfa_seeds = new ItemSeedFood(1, 4, UBlocks.alfalfa, Blocks.FARMLAND) public static final Item alfalfa_seeds = new ItemSeedFood(1, 4, UBlocks.alfalfa, Blocks.FARMLAND)
.setTranslationKey("alfalfa_seeds") .setTranslationKey("alfalfa_seeds")
.setRegistryName(Unicopia.MODID, "alfalfa_seeds") .setRegistryName(Unicopia.MODID, "alfalfa_seeds")
.setCreativeTab(CreativeTabs.MATERIALS); .setCreativeTab(CreativeTabs.MATERIALS);
public static final Item enchanted_torch = register(new BlockItem(UBlocks.enchanted_torch), "enchanted_torch"); public static final Item enchanted_torch = register(new BlockItem(UBlocks.enchanted_torch, new Item.Settings().group(ItemGroup.DECORATIONS)), "enchanted_torch");
public static final Item alfalfa_leaves = new FoodItem(1, 3, false) public static final Item alfalfa_leaves = register(new Item(new Item.Settings()
.setTranslationKey("alfalfa_leaves") .group(ItemGroup.FOOD)
.setRegistryName(Unicopia.MODID, "alfalfa_leaves"); .food(new FoodComponent.Builder()
.hunger(1)
.saturationModifier(3)
.build())), "alfalfa_leaves");
public static final Item cereal = new ItemCereal(Unicopia.MODID, "cereal", 9, 0.8F).setSugarAmount(1); public static final Item cereal = register(new SugaryItem(new Item.Settings()
public static final Item sugar_cereal = new ItemCereal(Unicopia.MODID, "sugar_cereal", 20, -2).setSugarAmount(110).setAlwaysEdible(); .group(ItemGroup.FOOD)
.food(new FoodComponent.Builder()
.hunger(9)
.saturationModifier(0.8F)
.build())
.maxCount(1)
.recipeRemainder(Items.BOWL), 1), "cereal");
public static final Item sugar_cereal = register(new SugaryItem(new Item.Settings()
.group(ItemGroup.FOOD)
.food(new FoodComponent.Builder()
.hunger(20)
.saturationModifier(-2)
.build())
.maxCount(1)
.recipeRemainder(Items.BOWL), 110), "sugar_cereal");
public static final TomatoItem tomato = new TomatoItem(Unicopia.MODID, "tomato", 4, 34); public static final TomatoItem tomato = register(new TomatoItem(4, 34), "tomato");
public static final RottenTomatoItem rotten_tomato = new RottenTomatoItem(Unicopia.MODID, "rotten_tomato", 4, 34); public static final RottenTomatoItem rotten_tomato = register(new RottenTomatoItem(4, 34), "rotten_tomato");
public static final TomatoItem cloudsdale_tomato = new TomatoItem(Unicopia.MODID, "cloudsdale_tomato", 16, 4); public static final TomatoItem cloudsdale_tomato = register(new TomatoItem(16, 4), "cloudsdale_tomato");
public static final RottenTomatoItem rotten_cloudsdale_tomato = new RottenTomatoItem(Unicopia.MODID, "rotten_cloudsdale_tomato", 4, 34); public static final RottenTomatoItem rotten_cloudsdale_tomato = register(new RottenTomatoItem(5, 34), "rotten_cloudsdale_tomato");
public static final TomatoSeedsItem tomato_seeds = new TomatoSeedsItem(Unicopia.MODID, "tomato_seeds"); public static final TomatoSeedsItem tomato_seeds = new TomatoSeedsItem(Unicopia.MODID, "tomato_seeds");
@ -155,19 +173,19 @@ public class UItems {
public static final Item apple_leaves = new BlockItem(UBlocks.apple_leaves); public static final Item apple_leaves = new BlockItem(UBlocks.apple_leaves);
public static final Item double_plant = new UItemFoodDelegate(Blocks.DOUBLE_PLANT, stack -> public static final Item double_plant = new DelegateFoodItem(Blocks.TALL_GRASS, stack ->
BlockDoublePlant.EnumPlantType.byMetadata(stack.getMetadata()).getTranslationKey() BlockDoublePlant.EnumPlantType.byMetadata(stack.getMetadata()).getTranslationKey()
).setFoodDelegate(new MultiItemEdible(new BushToxicityDeterminent())) ).setFoodDelegate(new DelegatedEdibleItem(new BushToxicityDeterminent()))
.setTranslationKey("doublePlant"); .setTranslationKey("doublePlant");
public static final Item tall_grass = new UItemFoodDelegate(Blocks.TALLGRASS, stack -> { public static final Item tall_grass = new DelegateFoodItem(Blocks.GRASS, stack -> {
switch (stack.getMetadata()) { switch (stack.getMetadata()) {
case 0: return "shrub"; case 0: return "shrub";
case 1: return "grass"; case 1: return "grass";
case 2: return "fern"; case 2: return "fern";
default: return ""; default: return "";
} }
}).setFoodDelegate(new MultiItemEdible(stack -> { }).setFoodDelegate(new DelegatedEdibleItem(stack -> {
switch (stack.getMetadata()) { switch (stack.getMetadata()) {
default: default:
case 0: return Toxicity.SAFE; case 0: return Toxicity.SAFE;
@ -176,63 +194,39 @@ public class UItems {
} }
})); }));
public static final Item yellow_flower = new UItemFoodDelegate(Blocks.YELLOW_FLOWER, stack -> public static final Item yellow_flower = new DelegateFoodItem(Blocks.YELLOW_FLOWER, stack ->
BlockFlower.EnumFlowerType.getType(BlockFlower.EnumFlowerColor.YELLOW, stack.getMetadata()).getTranslationKey() BlockFlower.EnumFlowerType.getType(BlockFlower.EnumFlowerColor.YELLOW, stack.getMetadata()).getTranslationKey()
).setFoodDelegate(new MultiItemEdible(new FlowerToxicityDeterminent(BlockFlower.EnumFlowerColor.YELLOW))) ).setFoodDelegate(new DelegatedEdibleItem(new FlowerToxicityDeterminent(BlockFlower.EnumFlowerColor.YELLOW)))
.setTranslationKey("flower"); .setTranslationKey("flower");
public static final Item red_flower = new UItemFoodDelegate(Blocks.RED_FLOWER, stack -> public static final Item red_flower = new DelegateFoodItem(Blocks.RED_FLOWER, stack ->
BlockFlower.EnumFlowerType.getType(BlockFlower.EnumFlowerColor.RED, stack.getMetadata()).getTranslationKey() BlockFlower.EnumFlowerType.getType(BlockFlower.EnumFlowerColor.RED, stack.getMetadata()).getTranslationKey()
).setFoodDelegate(new MultiItemEdible(new FlowerToxicityDeterminent(BlockFlower.EnumFlowerColor.RED))) ).setFoodDelegate(new DelegatedEdibleItem(new FlowerToxicityDeterminent(BlockFlower.EnumFlowerColor.RED)))
.setTranslationKey("rose"); .setTranslationKey("rose");
public static final Item daffodil_daisy_sandwich = new MultiItemEdible(Unicopia.MODID, "daffodil_daisy_sandwich", 3, 2, CookedToxicityDeterminent.instance) public static final Item daffodil_daisy_sandwich = new DelegatedEdibleItem(Unicopia.MODID, "daffodil_daisy_sandwich", 3, 2, CookedToxicityDeterminent.instance)
.setHasSubtypes(true); .setHasSubtypes(true);
public static final Item hay_burger = new MultiItemEdible(Unicopia.MODID, "hay_burger", 3, 4, CookedToxicityDeterminent.instance) public static final Item hay_burger = new DelegatedEdibleItem(Unicopia.MODID, "hay_burger", 3, 4, CookedToxicityDeterminent.instance)
.setHasSubtypes(true); .setHasSubtypes(true);
public static final Item hay_fries = new MultiItemEdible(Unicopia.MODID, "hay_fries", 1, 5, stack -> Toxicity.SAFE); public static final Item hay_fries = new DelegatedEdibleItem(Unicopia.MODID, "hay_fries", 1, 5, stack -> Toxicity.SAFE);
public static final Item salad = new MultiItemEdible(Unicopia.MODID, "salad", 4, 2, CookedToxicityDeterminent.instance) public static final Item salad = new DelegatedEdibleItem(Unicopia.MODID, "salad", 4, 2, CookedToxicityDeterminent.instance)
.setHasSubtypes(true) .setHasSubtypes(true)
.setContainerItem(Items.BOWL); .setContainerItem(Items.BOWL);
public static final Item wheat_worms = new MultiItemEdible(Unicopia.MODID, "wheat_worms", 1, 0, stack -> Toxicity.SEVERE); public static final Item wheat_worms = new DelegatedEdibleItem(Unicopia.MODID, "wheat_worms", 1, 0, stack -> Toxicity.SEVERE);
public static final Item mug = register(new Item(new Item.Settings().group(ItemGroup.MATERIALS)), "mug"); public static final Item mug = register(new Item(new Item.Settings().group(ItemGroup.MATERIALS)), "mug");
public static final Item apple_cider = new MultiItemEdible(Unicopia.MODID, "apple_cider", 4, 2, stack -> Toxicity.MILD) public static final Item apple_cider = new DelegatedEdibleItem(Unicopia.MODID, "apple_cider", 4, 2, stack -> Toxicity.MILD)
.setUseAction(UseAction.DRINK) .setUseAction(UseAction.DRINK)
.setContainerItem(mug) .setContainerItem(mug)
.setFull3D(); .setFull3D();
public static final Item juice = new MultiItemEdible(Unicopia.MODID, "juice", 2, 2, stack -> Toxicity.SAFE) public static final Item juice = new DelegatedEdibleItem(Unicopia.MODID, "juice", 2, 2, stack -> Toxicity.SAFE)
.setUseAction(UseAction.DRINK) .setUseAction(UseAction.DRINK)
.setContainerItem(Items.GLASS_BOTTLE); .setContainerItem(Items.GLASS_BOTTLE);
public static final Item burned_juice = new MultiItemEdible(Unicopia.MODID, "burned_juice", 3, 1, stack -> Toxicity.FAIR) public static final Item burned_juice = new DelegatedEdibleItem(Unicopia.MODID, "burned_juice", 3, 1, stack -> Toxicity.FAIR)
.setUseAction(UseAction.DRINK) .setUseAction(UseAction.DRINK)
.setContainerItem(Items.GLASS_BOTTLE); .setContainerItem(Items.GLASS_BOTTLE);
static void init(IForgeRegistry<Item> registry) {
RegistryLockSpinner.open(Item.REGISTRY, Items.class, r -> r
.replace(Items.APPLE, red_apple)
.replace(Item.getItemFromBlock(Blocks.TALLGRASS), tall_grass)
.replace(Item.getItemFromBlock(Blocks.DOUBLE_PLANT), double_plant)
.replace(Item.getItemFromBlock(Blocks.YELLOW_FLOWER), yellow_flower)
.replace(Item.getItemFromBlock(Blocks.RED_FLOWER), red_flower));
if (UClient.isClientSide()) {
BuildInTexturesBakery.getBuiltInTextures().add(new Identifier(Unicopia.MODID, "items/empty_slot_gem"));
}
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);
}
static void fixRecipes() {
new OreReplacer()
.registerAll(stack -> stack.getItem().getRegistryName().equals(red_apple.getRegistryName()))
.done();
}
private static <T extends Item> T register(T item, String namespace, String name) { private static <T extends Item> T register(T item, String namespace, String name) {
return Registry.ITEM.add(new Identifier(namespace, name), item); return Registry.ITEM.add(new Identifier(namespace, name), item);
} }
@ -240,7 +234,18 @@ public class UItems {
return register(item, name); return register(item, name);
} }
static void registerColors(ItemColors registry) { static void bootstrap() {
RegistryLockSpinner.open(Item.REGISTRY, Items.class, r -> r
.replace(Items.APPLE, red_apple)
.replace(Item.getItemFromBlock(Blocks.TALLGRASS), tall_grass)
.replace(Item.getItemFromBlock(Blocks.DOUBLE_PLANT), double_plant)
.replace(Item.getItemFromBlock(Blocks.YELLOW_FLOWER), yellow_flower)
.replace(Item.getItemFromBlock(Blocks.RED_FLOWER), red_flower));
if (ServerInteractionManager.isClientSide()) {
BuildInTexturesBakery.getBuiltInTextures().add(new Identifier(Unicopia.MODID, "items/empty_slot_gem"));
ItemColors registry;
registry.register((stack, tint) -> { registry.register((stack, tint) -> {
if (MAGI.test(MinecraftClient.getInstance().player)) { if (MAGI.test(MinecraftClient.getInstance().player)) {
return SpellRegistry.instance().getSpellTintFromStack(stack); return SpellRegistry.instance().getSpellTintFromStack(stack);
@ -250,5 +255,12 @@ public class UItems {
}, spell, curse); }, spell, curse);
} }
static void bootstrap() {} 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);
new OreReplacer()
.registerAll(stack -> stack.getItem().getRegistryName().equals(red_apple.getRegistryName()))
.done();
}
} }

View file

@ -1,100 +0,0 @@
package com.minelittlepony.unicopia;
import javax.annotation.Nonnull;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.potion.Potion;
public class UPotion extends StatusEffect {
private boolean isSilent;
private int tickDelay = 40;
@Nonnull
private IEffectApplicator applicator = IEffectApplicator.NONE;
public UPotion(String domain, String name, boolean isNegative, int tint) {
super(isNegative, tint);
setRegistryName(domain, name);
setPotionName("effect." + name);
}
public UPotion setSilent() {
isSilent = true;
return this;
}
public UPotion setApplicator(@Nonnull IEffectApplicator applicator) {
this.applicator = applicator;
return this;
}
public UPotion setTickDelay(int delay) {
tickDelay = delay;
return this;
}
@Override
public UPotion setIconIndex(int u, int v) {
super.setIconIndex(u, v);
return this;
}
@Override
public UPotion setEffectiveness(double effectiveness) {
super.setEffectiveness(effectiveness);
return this;
}
@Override
public boolean shouldRender(StatusEffectInstance effect) {
return !isSilent;
}
@Override
public boolean shouldRenderInvText(StatusEffectInstance effect) {
return !isSilent;
}
@Override
public boolean shouldRenderHUD(StatusEffectInstance effect) {
return !isSilent;
}
@Override
public void performEffect(LivingEntity entity, int amplifier) {
applicator.performEffect(this, entity, amplifier);
}
@Override
public boolean isInstant() {
return tickDelay > 0;
}
@Override
public boolean isReady(int duration, int amplifier) {
if (!isInstant()) {
int i = tickDelay >> amplifier;
if (i > 0) {
return duration % i == 0;
}
}
return duration > 0;
}
@FunctionalInterface
public interface IEffectApplicator {
IEffectApplicator NONE = (p, e, i) -> {};
void performEffect(Potion effect, LivingEntity target, int amplifier);
}
}

View file

@ -23,7 +23,6 @@ import com.minelittlepony.unicopia.inventory.gui.GuiSpellBook;
import com.minelittlepony.unicopia.network.MsgPlayerAbility; import com.minelittlepony.unicopia.network.MsgPlayerAbility;
import com.minelittlepony.unicopia.network.MsgPlayerCapabilities; import com.minelittlepony.unicopia.network.MsgPlayerCapabilities;
import com.minelittlepony.unicopia.network.MsgRequestCapabilities; import com.minelittlepony.unicopia.network.MsgRequestCapabilities;
import com.minelittlepony.unicopia.util.crafting.CraftingManager;
import com.minelittlepony.unicopia.world.UWorld; import com.minelittlepony.unicopia.world.UWorld;
public class Unicopia implements ModInitializer { public class Unicopia implements ModInitializer {
@ -33,25 +32,10 @@ public class Unicopia implements ModInitializer {
public static final Logger LOGGER = LogManager.getLogger(); public static final Logger LOGGER = LogManager.getLogger();
static InteractionManager interactionManager;
private static IChannel channel; private static IChannel channel;
private static CraftingManager craftingManager = new CraftingManager(MODID, "enchanting") {
@Override
protected void registerRecipeTypes(Map<String, Function<JsonObject, IRecipe>> types) {
super.registerRecipeTypes(types);
types.put("unicopia:crafting_spell", SpellRecipe::deserialize);
types.put("unicopia:crafting_special", SpecialRecipe::deserialize);
AffineIngredients.instance().load();
}
};
@Deprecated
public static CraftingManager getCraftingManager() {
return craftingManager;
}
public static IChannel getConnection() { public static IChannel getConnection() {
return channel; return channel;
} }
@ -76,13 +60,13 @@ public class Unicopia implements ModInitializer {
UBlocks.bootstrap(); UBlocks.bootstrap();
UItems.bootstrap(); UItems.bootstrap();
Commands.bootstrap(); Commands.bootstrap();
UContainers.bootstrap();
UWorld.instance().init(); UWorld.instance().init();
UClient.instance().preInit(); InteractionManager.instance().preInit();
UClient.instance().init(); InteractionManager.instance().init();
UClient.instance().postInit(); InteractionManager.instance().postInit();
UItems.fixRecipes(); UItems.fixRecipes();
} }

View file

@ -5,7 +5,7 @@ import javax.annotation.Nullable;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.entity.capabilities.IPlayer; import com.minelittlepony.unicopia.entity.capabilities.IPlayer;
import com.minelittlepony.unicopia.magic.spells.SpellChangelingTrap; import com.minelittlepony.unicopia.magic.spells.ChangelingTrapSpell;
public class PowerEngulf implements IPower<Hit> { public class PowerEngulf implements IPower<Hit> {
@ -47,7 +47,7 @@ public class PowerEngulf implements IPower<Hit> {
@Override @Override
public void apply(IPlayer player, Hit data) { public void apply(IPlayer player, Hit data) {
new SpellChangelingTrap().toss(player); new ChangelingTrapSpell().toss(player);
} }
@Override @Override

View file

@ -0,0 +1,128 @@
package com.minelittlepony.unicopia.block;
import javax.annotation.Nullable;
import com.minelittlepony.util.WorldEvent;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.DoorBlock;
import net.minecraft.block.Material;
import net.minecraft.block.enums.DoubleBlockHalf;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
public abstract class AbstractDoorBlock extends DoorBlock {
protected AbstractDoorBlock(Settings settings) {
super(settings);
}
protected WorldEvent getCloseSound() {
return isLockable() ? WorldEvent.IRON_DOOR_SLAM : WorldEvent.WOODEN_DOOR_SLAM;
}
protected WorldEvent getOpenSound() {
return isLockable() ? WorldEvent.IRON_DOOR_OPEN : WorldEvent.WOODEN_DOOR_OPEN;
}
@Override
public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
return toggleDoor(world, pos, false, true, player);
}
@Override
public void setOpen(World world, BlockPos pos, boolean open) {
toggleDoor(world, pos, open, false, null);
}
protected boolean isLockable() {
return material == Material.METAL;
}
protected boolean canBePowered() {
return true;
}
protected boolean canOpen(@Nullable PlayerEntity player) {
return player == null || material != Material.METAL;
}
protected boolean toggleDoor(World world, BlockPos pos, boolean open, boolean force, @Nullable PlayerEntity player) {
if (!canOpen(player)) {
return false;
}
BlockState state = world.getBlockState(pos);
if (state.getBlock() != this) {
return false;
}
BlockPos lower = getPrimaryDoorPos(state, pos);
BlockState mainDoor = pos == lower ? state : world.getBlockState(lower);
if (mainDoor.getBlock() != this) {
return false;
}
if (!force && mainDoor.get(OPEN) == open) {
return false;
}
state = mainDoor.cycle(OPEN);
world.setBlockState(lower, state, 10);
WorldEvent sound = state.get(OPEN) ? getOpenSound() : getCloseSound();
world.playLevelEvent(player, sound.getId(), pos, 0);
return true;
}
protected BlockPos getPrimaryDoorPos(BlockState state, BlockPos pos) {
return state.get(HALF) == DoubleBlockHalf.LOWER ? pos : pos.down();
}
@Override
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block sender, BlockPos blockPos_2, boolean boolean_1) {
if (!canBePowered()) {
return;
}
BlockPos otherHalf = pos.offset(state.get(HALF) == DoubleBlockHalf.LOWER ? Direction.UP : Direction.DOWN);
boolean powered = world.isReceivingRedstonePower(pos) || world.isReceivingRedstonePower(otherHalf);
if (sender != this && powered != state.get(POWERED)) {
world.setBlockState(pos, state.with(POWERED, powered), 2);
if (onPowerStateChanged(world, state.with(POWERED, powered), pos, powered)) {
playToggleSound(world, pos, powered);
}
}
}
protected void playToggleSound(World world, BlockPos pos, boolean powered) {
world.playLevelEvent(null, (powered ? getOpenSound() : getCloseSound()).getId(), pos, 0);
}
/**
* Called by the lower block when the powered state changes.
*/
protected boolean onPowerStateChanged(World world, BlockState state, BlockPos pos, boolean powered) {
if (powered != state.get(OPEN)) {
world.setBlockState(pos, state.with(OPEN, powered), 2);
return true;
}
return false;
}
}

View file

@ -1,151 +0,0 @@
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.util.WorldEvent;
import net.minecraft.block.AnvilBlock;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
public class BlockCloudAnvil extends AnvilBlock implements ICloudBlock {
public BlockCloudAnvil(String domain, String name) {
super();
setSoundType(SoundType.CLOTH);
setHardness(0.025F);
setResistance(2000);
setRegistryName(domain, name);
setTranslationKey(name);
}
@Override
public BlockRenderLayer getRenderLayer() {
return BlockRenderLayer.TRANSLUCENT;
}
@Override
public String getHarvestTool(BlockState state) {
return "shovel";
}
@Override
public int getHarvestLevel(BlockState state) {
return 0;
}
@Override
public void onFallenUpon(World world, BlockPos pos, Entity entityIn, float fallDistance) {
if (!applyLanding(entityIn, fallDistance)) {
super.onFallenUpon(world, pos, entityIn, fallDistance);
}
}
@Override
public void onEndFalling(World world, BlockPos pos, BlockState fallingState, BlockState hitState) {
WorldEvent.ENTITY_TAKEOFF.play(world, pos);
}
@Override
public void onBroken(World world, BlockPos pos) {
WorldEvent.ENTITY_TAKEOFF.play(world, pos);
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, BlockState state, PlayerEntity playerIn, EnumHand hand, Direction facing, float hitX, float hitY, float hitZ) {
return false;
}
@Override
protected void onStartFalling(EntityFallingBlock fallingEntity) {
fallingEntity.setHurtEntities(true);
}
@Override
public void onLanded(World worldIn, Entity entity) {
if (!applyRebound(entity)) {
super.onLanded(worldIn, entity);
}
}
@Override
public boolean isAir(BlockState state, BlockView world, BlockPos pos) {
return allowsFallingBlockToPass(state, world, pos);
}
@Override
public void updateTick(World world, BlockPos pos, BlockState state, Random rand) {
BlockState below = world.getBlockState(pos.down());
if (below.getBlock() instanceof ICloudBlock) {
if (((ICloudBlock)below.getBlock()).isDense(below)) {
return;
}
}
super.updateTick(world, pos, state, rand);
}
@Override
public void onEntityCollision(World w, BlockPos pos, BlockState state, Entity entity) {
if (!applyBouncyness(state, entity)) {
super.onEntityCollision(w, pos, state, entity);
}
}
@Override
public boolean canHarvestBlock(BlockView world, BlockPos pos, PlayerEntity player) {
return getCanInteract(world.getBlockState(pos), player);
}
@Override
public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items) {
items.add(new ItemStack(this));
}
@Override
public boolean canEntityDestroy(BlockState state, BlockView world, BlockPos pos, Entity entity) {
return getCanInteract(state, entity) && super.canEntityDestroy(state, world, pos, entity);
}
@Deprecated
public void addCollisionBoxToList(BlockState state, World worldIn, BlockPos pos, Box entityBox, List<Box> collidingBoxes, @Nullable Entity entity, boolean p_185477_7_) {
if (getCanInteract(state, entity)) {
super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entity, p_185477_7_);
}
}
@Deprecated
@Override
public RayTraceResult collisionRayTrace(BlockState blockState, World worldIn, BlockPos pos, Vec3d start, Vec3d end) {
if (!handleRayTraceSpecialCases(worldIn, pos, blockState)) {
return super.collisionRayTrace(blockState, worldIn, pos, start, end);
}
return null;
}
@Deprecated
@Override
public float getPlayerRelativeBlockHardness(BlockState state, PlayerEntity player, World worldIn, BlockPos pos) {
if (!CloudType.NORMAL.canInteract(player)) {
return -1;
}
return super.getPlayerRelativeBlockHardness(state, player, worldIn, pos);
}
@Override
public CloudType getCloudMaterialType(BlockState blockState) {
return CloudType.NORMAL;
}
}

View file

@ -1,137 +0,0 @@
package com.minelittlepony.unicopia.block;
import java.util.List;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.CloudType;
import net.minecraft.block.BlockRenderLayer;
import net.minecraft.block.Material;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
public class BlockCloudBanister extends BlockCloudFence {
public static final double l = 11/16D;
public static final double d = 5/16D;
public static final double h = 2/16D;
public static final Box SOUTH_AABB = new Box(d, 0, l, l, h, 1);
public static final Box WEST_AABB = new Box(0, 0, d, d, h, l);
public static final Box NORTH_AABB = new Box(d, 0, 0, l, h, d);
public static final Box EAST_AABB = new Box(l, 0, d, 1, h, l);
public static final Box[] BOUNDING_BOXES = new Box[] {
new Box(d, 0, d, l, h, l),
new Box(d, 0, d, l, h, 1),
new Box(0, 0, d, l, h, l),
new Box(0, 0, d, l, h, 1),
new Box(d, 0, 0, l, h, l),
new Box(d, 0, 0, l, h, 1),
new Box(0, 0, 0, l, h, l),
new Box(0, 0, 0, l, h, 1),
new Box(d, 0, d, 1, h, l),
new Box(d, 0, d, 1, h, 1),
new Box(0, 0, d, 1, h, l),
new Box(0, 0, d, 1, h, 1),
new Box(d, 0, 0, 1, h, l),
new Box(d, 0, 0, 1, h, 1),
new Box(0, 0, 0, 1, h, l),
new Box(0, 0, 0, 1, h, 1)
};
public BlockCloudBanister(Material material, String domain, String name) {
super(material, CloudType.ENCHANTED, domain, name);
}
@Override
public BlockRenderLayer getRenderLayer() {
return BlockRenderLayer.SOLID;
}
@Override
public boolean canConnectTo(BlockView world, BlockPos pos, Direction facing) {
BlockState myState = world.getBlockState(pos);
return myState.getBlock() instanceof BlockCloudBanister
&& super.canConnectTo(world, pos, facing);
}
@Override
public boolean canBeConnectedTo(BlockView world, BlockPos pos, Direction facing) {
BlockState state = world.getBlockState(pos.offset(facing));
return state.getBlock() instanceof BlockCloudBanister
&& state.getMaterial() == world.getBlockState(pos).getMaterial();
}
@Deprecated
@Override
public void addCollisionBoxToList(BlockState state, World world, BlockPos pos, Box entityBox, List<Box> collidingBoxes, @Nullable Entity entity, boolean isActualState) {
if (!getCanInteract(state, entity)) {
return;
}
if (!isActualState) {
state = state.getActualState(world, pos);
}
if (state.getValue(NORTH)) {
addCollisionBoxToList(pos, entityBox, collidingBoxes, NORTH_AABB);
}
if (state.getValue(EAST)) {
addCollisionBoxToList(pos, entityBox, collidingBoxes, EAST_AABB);
}
if (state.getValue(SOUTH)) {
addCollisionBoxToList(pos, entityBox, collidingBoxes, SOUTH_AABB);
}
if (state.getValue(WEST)) {
addCollisionBoxToList(pos, entityBox, collidingBoxes, WEST_AABB);
}
}
@Override
public boolean isTopSolid(BlockState state) {
return false;
}
@Override
public boolean canPlaceTorchOnTop(BlockState state, BlockView world, BlockPos pos) {
return false;
}
@Override
public Box getBoundingBox(BlockState state, BlockView source, BlockPos pos) {
state = state.getActualState(source, pos);
return BOUNDING_BOXES[getBoundingBoxIdx(state)];
}
public static int getBoundingBoxIdx(BlockState state) {
int i = 0;
if (state.getValue(NORTH)) {
i |= 1 << Direction.NORTH.getHorizontalIndex();
}
if (state.getValue(EAST)) {
i |= 1 << Direction.EAST.getHorizontalIndex();
}
if (state.getValue(SOUTH)) {
i |= 1 << Direction.SOUTH.getHorizontalIndex();
}
if (state.getValue(WEST)) {
i |= 1 << Direction.WEST.getHorizontalIndex();
}
return i;
}
}

View file

@ -1,61 +1,41 @@
package com.minelittlepony.unicopia.block; package com.minelittlepony.unicopia.block;
import java.util.function.Supplier;
import com.minelittlepony.unicopia.CloudType; import com.minelittlepony.unicopia.CloudType;
import com.minelittlepony.unicopia.UMaterials;
import net.minecraft.block.SoundType; import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.minecraft.block.material.MapColor; import net.minecraft.block.BlockRenderLayer;
import net.minecraft.block.material.Material; import net.minecraft.block.BlockState;
import net.minecraft.block.state.BlockState;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item; import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.Hand;
import net.minecraft.util.Direction; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
public class BlockCloudDoor extends UDoor implements ICloudBlock { public class BlockCloudDoor extends AbstractDoorBlock implements ICloudBlock {
public BlockCloudDoor(Material material, String domain, String name, Supplier<Item> theItem) { @SuppressWarnings("deprecation")
super(material, domain, name, theItem); public BlockCloudDoor() {
super(FabricBlockSettings.of(UMaterials.cloud)
setSoundType(SoundType.CLOTH); .sounds(BlockSoundGroup.WOOL)
setHardness(3); .hardness(3)
setResistance(200); .resistance(200)
.breakByTool(net.fabricmc.fabric.api.tools.FabricToolTags.SHOVELS, 0)
.build());
} }
@Override @Override
public MapColor getMapColor(BlockState state, BlockView worldIn, BlockPos pos) { public boolean activate(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
return blockMapColor; return getCanInteract(state, player) && super.activate(state, worldIn, pos, player, hand, hit);
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, BlockState state, PlayerEntity player, EnumHand hand, Direction facing, float hitX, float hitY, float hitZ) {
if (!getCanInteract(state, player)) {
return false;
}
return super.onBlockActivated(worldIn, pos, state, player, hand, facing, hitX, hitY, hitZ);
}
@Override
public String getHarvestTool(BlockState state) {
return "shovel";
}
@Override
public int getHarvestLevel(BlockState state) {
return 0;
} }
@Deprecated @Deprecated
@Override @Override
public float getBlockHardness(BlockState blockState, World world, BlockPos pos) { public float getHardness(BlockState blockState, BlockView world, BlockPos pos) {
float hardness = super.getBlockHardness(blockState, world, pos); float hardness = super.getHardness(blockState, world, pos);
return Math.max(hardness, Math.min(60, hardness + (pos.getY() - 100))); return Math.max(hardness, Math.min(60, hardness + (pos.getY() - 100)));
} }
@ -66,22 +46,17 @@ public class BlockCloudDoor extends UDoor implements ICloudBlock {
} }
@Override @Override
public void onEntityCollision(World w, BlockPos pos, BlockState state, Entity entity) { public void onEntityCollision(BlockState state, World w, BlockPos pos, Entity entity) {
if (!applyBouncyness(state, entity)) { if (!applyBouncyness(state, entity)) {
super.onEntityCollision(w, pos, state, entity); super.onEntityCollision(state, w, pos, entity);
} }
} }
@Override
public boolean canEntityDestroy(BlockState state, BlockView world, BlockPos pos, Entity entity) {
return getCanInteract(state, entity) && super.canEntityDestroy(state, world, pos, entity);
}
@Deprecated @Deprecated
@Override @Override
public float getPlayerRelativeBlockHardness(BlockState state, PlayerEntity player, World worldIn, BlockPos pos) { public float calcBlockBreakingDelta(BlockState state, PlayerEntity player, BlockView worldIn, BlockPos pos) {
if (CloudType.NORMAL.canInteract(player)) { if (CloudType.NORMAL.canInteract(player)) {
return super.getPlayerRelativeBlockHardness(state, player, worldIn, pos); return super.calcBlockBreakingDelta(state, player, worldIn, pos);
} }
return -1; return -1;
} }

View file

@ -1,129 +0,0 @@
package com.minelittlepony.unicopia.block;
import java.util.List;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.CloudType;
import net.minecraft.block.BlockRenderLayer;
import net.minecraft.block.BlockState;
import net.minecraft.block.FenceBlock;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
public class BlockCloudFence extends FenceBlock implements ICloudBlock {
private final CloudType variant;
public BlockCloudFence(Material material, CloudType variant, String domain, String name) {
super(material, material.getMaterialMapColor());
setTranslationKey(name);
setRegistryName(domain, name);
setHardness(0.5f);
setResistance(1.0F);
setLightOpacity(20);
setSoundType(SoundType.CLOTH);
useNeighborBrightness = true;
this.variant = variant;
}
@Override
public boolean isTranslucent(BlockState state) {
return variant == CloudType.NORMAL;
}
@Override
public boolean isOpaqueCube(BlockState state) {
return false;
}
@Override
public boolean isFullCube(BlockState state) {
return false;
}
@Override
public boolean isAir(BlockState state, BlockView world, BlockPos pos) {
return allowsFallingBlockToPass(state, world, pos);
}
@Override
public boolean isNormalCube(BlockState state) {
return false;
}
@Override
public CloudType getCloudMaterialType(BlockState blockState) {
return variant;
}
@Override
public BlockRenderLayer getRenderLayer() {
return BlockRenderLayer.TRANSLUCENT;
}
@Override
public void onFallenUpon(World world, BlockPos pos, Entity entityIn, float fallDistance) {
if (!applyLanding(entityIn, fallDistance)) {
super.onFallenUpon(world, pos, entityIn, fallDistance);
}
}
@Override
public void onEntityLand(BlockView world, Entity entity) {
if (!applyRebound(entity)) {
super.onEntityLand(world, entity);
}
}
public boolean canConnectTo(BlockView world, BlockPos pos, Direction facing) {
BlockState myState = world.getBlockState(pos);
return !(myState.getBlock() instanceof BlockCloudBanister)
&& super.canConnectTo(world, pos, facing);
}
@Override
public void onEntityCollision(BlockState state, World w, BlockPos pos, Entity entity) {
if (!applyBouncyness(state, entity)) {
super.onEntityCollision(state, w, pos, entity);
}
}
@Override
public boolean canEntityDestroy(BlockState state, BlockView world, BlockPos pos, Entity entity) {
return getCanInteract(state, entity) && super.canEntityDestroy(state, world, pos, entity);
}
@Deprecated
public void addCollisionBoxToList(BlockState state, World worldIn, BlockPos pos, Box entityBox, List<Box> collidingBoxes, @Nullable Entity entity, boolean isActualState) {
if (getCanInteract(state, entity)) {
super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entity, isActualState);
}
}
@Deprecated
@Override
public float calcBlockBreakingDelta(BlockState state, PlayerEntity player, BlockView world, BlockPos pos) {
if (CloudType.NORMAL.canInteract(player)) {
return super.calcBlockBreakingDelta(state, player, world, pos);
}
return -1;
}
@Deprecated
@Override
public RayTraceResult collisionRayTrace(BlockState state, World world, BlockPos pos, Vec3d start, Vec3d end) {
if (!handleRayTraceSpecialCases(world, pos, state)) {
return super.collisionRayTrace(state, world, pos, start, end);
}
return null;
}
}

View file

@ -1,147 +0,0 @@
package com.minelittlepony.unicopia.block;
import java.util.List;
import java.util.Random;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.CloudType;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.block.StairsBlock;
import net.minecraft.block.enums.BlockHalf;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
public abstract class BlockCloudSlab<T extends Block & ICloudBlock> extends USlab<T> implements ICloudBlock {
public BlockCloudSlab(T modelBlock, BlockCloudSlab<? extends T> single, Material material, String domain, String name) {
super(modelBlock, single, material, domain, name);
}
@SuppressWarnings("deprecation")
@Override
public boolean isTopSolid(BlockState state) {
return getCloudMaterialType(state) == CloudType.ENCHANTED && super.isTopSolid(state);
}
@SuppressWarnings("deprecation")
@FUF(reason = "...Really?")
public boolean isSideSolid(BlockState base_state, BlockAccess world, BlockPos pos, Direction side) {
return getCloudMaterialType(base_state) == CloudType.ENCHANTED && super.isSideSolid(base_state, world, pos, side);
}
@Override
@Deprecated
public void addCollisionBoxToList(BlockState state, World worldIn, BlockPos pos, Box entityBox, List<Box> collidingBoxes, @Nullable Entity entity, boolean p_185477_7_) {
if (getCanInteract(state, entity)) {
super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entity, p_185477_7_);
}
}
@Deprecated
@Override
public RayTraceResult collisionRayTrace(BlockState blockState, World worldIn, BlockPos pos, Vec3d start, Vec3d end) {
if (handleRayTraceSpecialCases(worldIn, pos, blockState)) {
return null;
}
return super.collisionRayTrace(blockState, worldIn, pos, start, end);
}
@Override
public CloudType getCloudMaterialType(BlockState blockState) {
return modelBlock.getCloudMaterialType(blockState);
}
public static class Single<T extends Block & ICloudBlock> extends BlockCloudSlab<T> {
public final Double<T> doubleSlab;
public Single(T modelBlock, Material material, String domain, String name) {
super(modelBlock, null, material, domain, name);
doubleSlab = new Double<>(this, domain, "double_" + name);
}
@Override
public boolean isDouble() {
return false;
}
@Override
public boolean isSideInvisible(BlockState state, BlockState beside, Direction face) {
if (beside.getBlock() instanceof ICloudBlock) {
ICloudBlock cloud = ((ICloudBlock)beside.getBlock());
if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) {
BlockHalf half = state.get(HALF);
if (beside.getBlock() instanceof BlockCloudStairs) {
return beside.get(StairsBlock.HALF).ordinal() == state.get(HALF).ordinal()
&& beside.get(Properties.FACING) == face;
}
if (face == Direction.DOWN) {
return half == BlockHalf.BOTTOM;
}
if (face == Direction.UP) {
return half == BlockHalf.TOP;
}
if (beside.getBlock() == this) {
return beside.get(HALF) == state.get(HALF);
}
}
}
return false;
}
}
public static class Double<T extends Block & ICloudBlock> extends BlockCloudSlab<T> {
public final Single<T> singleSlab;
public Double(Single<T> single, String domain, String name) {
super(single.modelBlock, single, single.material, domain, name);
this.singleSlab = single;
}
@Override
public boolean isDouble() {
return true;
}
@Override
public boolean doesSideBlockRendering(BlockState state, BlockView world, BlockPos pos, Direction face) {
BlockState beside = world.getBlockState(pos.offset(face));
if (beside.getBlock() instanceof ICloudBlock) {
ICloudBlock cloud = ((ICloudBlock)beside.getBlock());
if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) {
return true;
}
}
return false;
}
@Override
public Item getItemDropped(BlockState state, Random rand, int fortune) {
return Item.getItemFromBlock(singleSlab);
}
}
}

View file

@ -23,29 +23,8 @@ import net.minecraft.world.World;
public class BlockCloudStairs extends UStairs implements ICloudBlock { public class BlockCloudStairs extends UStairs implements ICloudBlock {
public BlockCloudStairs(BlockState inherited, String domain, String name) { public BlockCloudStairs(BlockState inherited) {
super(inherited, domain, name); super(inherited);
}
@Override
public boolean isAir(BlockState state, BlockView world, BlockPos pos) {
return allowsFallingBlockToPass(state, world, pos);
}
@Override
public void addCollisionBoxToList(BlockState state, World worldIn, BlockPos pos, Box entityBox, List<Box> collidingBoxes, @Nullable Entity entity, boolean p_185477_7_) {
if (getCanInteract(baseBlockState, entity)) {
super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entity, p_185477_7_);
}
}
@Deprecated
@Override
public HitResult collisionRayTrace(BlockState blockState, World worldIn, BlockPos pos, Vec3d start, Vec3d end) {
if (handleRayTraceSpecialCases(worldIn, pos, blockState)) {
return null;
}
return super.collisionRayTrace(blockState, worldIn, pos, start, end);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -61,10 +40,7 @@ public class BlockCloudStairs extends UStairs implements ICloudBlock {
} }
@Override @Override
public boolean doesSideBlockRendering(BlockState state, BlockView world, BlockPos pos, Direction face) { public boolean isSideInvisible(BlockState state, BlockState beside, Direction face) {
BlockState beside = world.getBlockState(pos.offset(face));
if (beside.getBlock() instanceof ICloudBlock) { if (beside.getBlock() instanceof ICloudBlock) {
ICloudBlock cloud = ((ICloudBlock)beside.getBlock()); ICloudBlock cloud = ((ICloudBlock)beside.getBlock());
@ -97,7 +73,7 @@ public class BlockCloudStairs extends UStairs implements ICloudBlock {
return sideIsBack return sideIsBack
|| (sideIsSide && bsideIsSide && front == bfront && half == bhalf); || (sideIsSide && bsideIsSide && front == bfront && half == bhalf);
} else if (beside.getBlock() instanceof BlockCloudSlab) { } else if (beside.getBlock() instanceof CloudSlabBlock) {
SlabType bhalf = beside.get(SlabBlock.TYPE); SlabType bhalf = beside.get(SlabBlock.TYPE);
if (face == Direction.UP || face == Direction.DOWN) { if (face == Direction.UP || face == Direction.DOWN) {

View file

@ -1,48 +0,0 @@
package com.minelittlepony.unicopia.block;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.EquinePredicates;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
public class BlockDiamondDoor extends UDoor {
public BlockDiamondDoor(String domain, String name, Supplier<Item> theItem) {
super(Material.IRON, domain, name, theItem);
setSoundType(SoundType.METAL);
setHardness(5.0F);
}
@Override
@Deprecated
public MapColor getMapColor(BlockState state, BlockView worldIn, BlockPos pos) {
return MapColor.DIAMOND;
}
@Override
protected boolean canOpen(@Nullable PlayerEntity player) {
return EquinePredicates.MAGI.test(player);
}
@Override
protected boolean onPowerStateChanged(World world, BlockState state, BlockPos pos, boolean powered) {
if (state.getValue(OPEN)) {
world.setBlockState(pos, state.with(OPEN, false), 2);
return true;
}
return false;
}
}

View file

@ -1,110 +0,0 @@
package com.minelittlepony.unicopia.block;
import java.util.function.Supplier;
import net.minecraft.block.BlockDoor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockState;
import net.minecraft.item.Item;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
public class BlockDutchDoor extends UDoor {
public BlockDutchDoor(Material material, String domain, String name, Supplier<Item> theItem) {
super(material, domain, name, theItem);
}
@Override
protected BlockPos getPrimaryDoorPos(BlockState state, BlockPos pos) {
return pos;
}
@Override
public boolean isPassable(BlockView world, BlockPos pos) {
return world.getBlockState(pos).getValue(OPEN);
}
@Override
protected boolean onPowerStateChanged(World world, BlockState state, BlockPos pos, boolean powered) {
boolean result = super.onPowerStateChanged(world, state, pos, powered);
BlockState upper = world.getBlockState(pos.up());
if (upper.getBlock() == this && upper.getValue(OPEN) != powered) {
world.setBlockState(pos.up(), upper.with(OPEN, powered));
return true;
}
return result;
}
// UPPER - HALF/HINGE/POWER{/OPEN}
// LOWER - HALF/FACING/FACING/OPEN
@Override
public BlockState getActualState(BlockState state, BlockView world, BlockPos pos) {
// copy properties in stored by the sibling block
if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER) {
BlockState other = world.getBlockState(pos.up());
if (other.getBlock() == this) {
return state.with(HINGE, other.getValue(HINGE))
.with(POWERED, other.getValue(POWERED));
}
} else {
BlockState other = world.getBlockState(pos.down());
if (other.getBlock() == this) {
return state.with(FACING, other.getValue(FACING));
}
}
return state;
}
@Override
public BlockState getStateFromMeta(int meta) {
boolean upper = (meta & 8) != 0;
BlockState state = getDefaultState()
.with(HALF, upper ? EnumDoorHalf.UPPER : EnumDoorHalf.LOWER)
.with(OPEN, (meta & 4) != 0);
if (upper) {
return state.with(POWERED, (meta & 1) != 0)
.with(HINGE, (meta & 2) != 0 ? EnumHingePosition.RIGHT : EnumHingePosition.LEFT);
}
return state.with(FACING, Direction.byHorizontalIndex(meta & 3).rotateYCCW());
}
@Override
public int getMetaFromState(BlockState state) {
int i = 0;
if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER) {
i |= 8;
if (state.getValue(POWERED)) {
i |= 1;
}
if (state.getValue(HINGE) == BlockDoor.EnumHingePosition.RIGHT) {
i |= 2;
}
} else {
i |= state.getValue(FACING).rotateY().getHorizontalIndex();
}
if (state.getValue(OPEN)) {
i |= 4;
}
return i;
}
}

View file

@ -25,6 +25,7 @@ import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
import net.minecraft.world.ViewableWorld;
import net.minecraft.world.World; import net.minecraft.world.World;
public class BlockTomatoPlant extends CropBlock { public class BlockTomatoPlant extends CropBlock {
@ -65,12 +66,13 @@ public class BlockTomatoPlant extends CropBlock {
return UItems.tomato; return UItems.tomato;
} }
public boolean canPlaceBlockAt(World world, BlockPos pos) { @Override
public boolean canPlaceAt(BlockState state, ViewableWorld world, BlockPos pos) {
if (world.getBlockState(pos.down()).getBlock() instanceof BlockTomatoPlant) { if (world.getBlockState(pos.down()).getBlock() instanceof BlockTomatoPlant) {
return true; return true;
} }
return super.canPlaceBlockAt(world, pos); return super.canPlaceAt(state, world, pos);
} }
@Override @Override

View file

@ -0,0 +1,103 @@
package com.minelittlepony.unicopia.block;
import java.util.Random;
import com.minelittlepony.unicopia.CloudType;
import com.minelittlepony.util.WorldEvent;
import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.minecraft.block.AnvilBlock;
import net.minecraft.block.BlockRenderLayer;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
public class CloudAnvilBlock extends AnvilBlock implements ICloudBlock {
@SuppressWarnings("deprecation")
public CloudAnvilBlock() {
super(FabricBlockSettings.of(Material.WOOL)
.strength(0.025F, 1)
.resistance(2000)
.breakByTool(net.fabricmc.fabric.api.tools.FabricToolTags.SHOVELS, 0)
.sounds(BlockSoundGroup.WOOL)
.ticksRandomly()
.build()
);
}
@Override
public BlockRenderLayer getRenderLayer() {
return BlockRenderLayer.TRANSLUCENT;
}
@Override
public void onLandedUpon(World world, BlockPos pos, Entity entityIn, float fallDistance) {
if (!applyLanding(entityIn, fallDistance)) {
super.onLandedUpon(world, pos, entityIn, fallDistance);
}
}
@Override
public void onLanding(World world, BlockPos pos, BlockState fallingState, BlockState hitState) {
WorldEvent.ENTITY_TAKEOFF.play(world, pos);
}
@Override
public void onDestroyedOnLanding(World world, BlockPos pos) {
WorldEvent.ENTITY_TAKEOFF.play(world, pos);
}
@Override
public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
return false;
}
@Override
public void onEntityLand(BlockView world, Entity entity) {
if (!applyRebound(entity)) {
super.onEntityLand(world, entity);
}
}
@Override
public void onScheduledTick(BlockState state, World world, BlockPos pos, Random rand) {
BlockState below = world.getBlockState(pos.down());
if (below.getBlock() instanceof ICloudBlock) {
if (((ICloudBlock)below.getBlock()).isDense(below)) {
return;
}
}
super.onScheduledTick(state, world, pos, rand);
}
@Override
public void onEntityCollision(BlockState state, World w, BlockPos pos, Entity entity) {
if (!applyBouncyness(state, entity)) {
super.onEntityCollision(state, w, pos, entity);
}
}
@Deprecated
@Override
public float calcBlockBreakingDelta(BlockState state, PlayerEntity player, BlockView world, BlockPos pos) {
if (!CloudType.NORMAL.canInteract(player)) {
return -1;
}
return super.calcBlockBreakingDelta(state, player, world, pos);
}
@Override
public CloudType getCloudMaterialType(BlockState blockState) {
return CloudType.NORMAL;
}
}

View file

@ -0,0 +1,57 @@
package com.minelittlepony.unicopia.block;
import java.util.List;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.CloudType;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderLayer;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
public class CloudBanisterBlock extends CloudFenceBlock {
public static final float l = 11;
public static final float d = 5;
public static final float h = 2;
public static final Box SOUTH_AABB = new Box(d, 0, l, l, h, 1);
public static final Box WEST_AABB = new Box(0, 0, d, d, h, l);
public static final Box NORTH_AABB = new Box(d, 0, 0, l, h, d);
public static final Box EAST_AABB = new Box(l, 0, d, 1, h, l);
public CloudBanisterBlock(Material material) {
super(material, CloudType.ENCHANTED);
this.collisionShapes = this.createShapes(l, d, h, 0.0F, d);
this.boundingShapes = this.createShapes(l, d, h, 0.0F, d);
}
@Override
public BlockRenderLayer getRenderLayer() {
return BlockRenderLayer.SOLID;
}
@Override
public boolean canConnect(BlockState myState, boolean bool, Direction facing) {
return myState.getBlock() instanceof CloudBanisterBlock
&& super.canConnect(myState, bool, facing);
}
@Override
public boolean canConnect(BlockView world, BlockPos pos, Direction facing) {
BlockState state = world.getBlockState(pos.offset(facing));
return state.getBlock() instanceof CloudBanisterBlock
&& state.getMaterial() == world.getBlockState(pos).getMaterial();
}
}

View file

@ -1,10 +1,7 @@
package com.minelittlepony.unicopia.block; package com.minelittlepony.unicopia.block;
import java.util.List;
import java.util.Random; import java.util.Random;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.CloudType; import com.minelittlepony.unicopia.CloudType;
import com.minelittlepony.unicopia.SpeciesList; import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.UBlocks; import com.minelittlepony.unicopia.UBlocks;
@ -19,18 +16,16 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.sound.BlockSoundGroup; import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
public class BlockCloud extends Block implements ICloudBlock, ITillable { public class CloudBlock extends Block implements ICloudBlock, ITillable {
private final CloudType variant; private final CloudType variant;
public BlockCloud(Material material, CloudType variant, String domain, String name) { public CloudBlock(Material material, CloudType variant) {
super(FabricBlockSettings.of(material) super(FabricBlockSettings.of(material)
.strength(0.5F, 1) .strength(0.5F, 1)
.sounds(BlockSoundGroup.WOOL) .sounds(BlockSoundGroup.WOOL)
@ -69,7 +64,7 @@ public class BlockCloud extends Block implements ICloudBlock, ITillable {
return variant == CloudType.NORMAL ? BlockRenderLayer.TRANSLUCENT : super.getRenderLayer(); return variant == CloudType.NORMAL ? BlockRenderLayer.TRANSLUCENT : super.getRenderLayer();
} }
@Deprecated /*@Deprecated
@Override @Override
public boolean isSideSolid(BlockState base_state, BlockView world, BlockPos pos, Direction side) { public boolean isSideSolid(BlockState base_state, BlockView world, BlockPos pos, Direction side) {
if (side == Direction.UP && (variant == CloudType.ENCHANTED || world.getBlockState(pos.up()).getBlock() instanceof ICloudBlock)) { if (side == Direction.UP && (variant == CloudType.ENCHANTED || world.getBlockState(pos.up()).getBlock() instanceof ICloudBlock)) {
@ -77,13 +72,10 @@ public class BlockCloud extends Block implements ICloudBlock, ITillable {
} }
return super.isSideSolid(base_state, world, pos, side); return super.isSideSolid(base_state, world, pos, side);
} }*/
@Override @Override
public boolean doesSideBlockRendering(BlockState state, BlockView world, BlockPos pos, Direction face) { public boolean isSideInvisible(BlockState state, BlockState beside, Direction face) {
BlockState beside = world.getBlockState(pos.offset(face));
if (beside.getBlock() instanceof ICloudBlock) { if (beside.getBlock() instanceof ICloudBlock) {
ICloudBlock cloud = ((ICloudBlock)beside.getBlock()); ICloudBlock cloud = ((ICloudBlock)beside.getBlock());
@ -92,47 +84,35 @@ public class BlockCloud extends Block implements ICloudBlock, ITillable {
} }
} }
return super.doesSideBlockRendering(state, world, pos, face); return super.isSideInvisible(state, beside, face);
} }
@Override @Override
public void onFallenUpon(World world, BlockPos pos, Entity entityIn, float fallDistance) { public void onLandedUpon(World world, BlockPos pos, Entity entityIn, float fallDistance) {
if (!applyLanding(entityIn, fallDistance)) { if (!applyLanding(entityIn, fallDistance)) {
super.onFallenUpon(world, pos, entityIn, fallDistance); super.onLandedUpon(world, pos, entityIn, fallDistance);
} }
} }
@Override @Override
public void onLanded(World worldIn, Entity entity) { public void onEntityLand(BlockView world, Entity entity) {
if (!applyRebound(entity)) { if (!applyRebound(entity)) {
super.onLanded(worldIn, entity); super.onEntityLand(world, entity);
} }
} }
@Override @Override
public void onEntityCollision(World w, BlockPos pos, BlockState state, Entity entity) { public void onEntityCollision(BlockState state, World w, BlockPos pos, Entity entity) {
if (!applyBouncyness(state, entity)) { if (!applyBouncyness(state, entity)) {
super.onEntityCollision(w, pos, state, entity); super.onEntityCollision(state, w, pos, entity);
}
}
@Override
public boolean canEntityDestroy(BlockState state, BlockView world, BlockPos pos, Entity entity) {
return getCanInteract(state, entity) && super.canEntityDestroy(state, world, pos, entity);
}
@Deprecated
public void addCollisionBoxToList(BlockState state, World worldIn, BlockPos pos, Box entityBox, List<Box> collidingBoxes, @Nullable Entity entity, boolean p_185477_7_) {
if (getCanInteract(state, entity)) {
super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entity, p_185477_7_);
} }
} }
@Deprecated @Deprecated
@Override @Override
public float getPlayerRelativeBlockHardness(BlockState state, PlayerEntity player, World worldIn, BlockPos pos) { public float calcBlockBreakingDelta(BlockState state, PlayerEntity player, BlockView worldIn, BlockPos pos) {
if (CloudType.NORMAL.canInteract(player)) { if (CloudType.NORMAL.canInteract(player)) {
return super.getPlayerRelativeBlockHardness(state, player, worldIn, pos); return super.calcBlockBreakingDelta(state, player, worldIn, pos);
} }
return -1; return -1;
} }
@ -142,15 +122,6 @@ public class BlockCloud extends Block implements ICloudBlock, ITillable {
return variant; return variant;
} }
@Deprecated
@Override
public RayTraceResult collisionRayTrace(BlockState blockState, World worldIn, BlockPos pos, Vec3d start, Vec3d end) {
if (!handleRayTraceSpecialCases(worldIn, pos, blockState)) {
return super.collisionRayTrace(blockState, worldIn, pos, start, end);
}
return null;
}
@Override @Override
public boolean canBeTilled(ItemStack hoe, PlayerEntity player, World world, BlockState state, BlockPos pos) { public boolean canBeTilled(ItemStack hoe, PlayerEntity player, World world, BlockState state, BlockPos pos) {
return SpeciesList.instance().getPlayer(player).getSpecies().canInteractWithClouds() return SpeciesList.instance().getPlayer(player).getSpecies().canInteractWithClouds()

View file

@ -0,0 +1,87 @@
package com.minelittlepony.unicopia.block;
import com.minelittlepony.unicopia.CloudType;
import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.minecraft.block.BlockRenderLayer;
import net.minecraft.block.BlockState;
import net.minecraft.block.FenceBlock;
import net.minecraft.block.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
public class CloudFenceBlock extends FenceBlock implements ICloudBlock {
private final CloudType variant;
public CloudFenceBlock(Material material, CloudType variant) {
super(FabricBlockSettings.of(material)
.hardness(0.5F)
.resistance(1)
.sounds(BlockSoundGroup.WOOL)
.build());
this.variant = variant;
}
@Override
public boolean isTranslucent(BlockState state, BlockView world, BlockPos pos) {
return variant == CloudType.NORMAL;
}
@Override
public boolean isOpaque(BlockState state) {
return false;
}
@Override
public CloudType getCloudMaterialType(BlockState blockState) {
return variant;
}
@Override
public BlockRenderLayer getRenderLayer() {
return BlockRenderLayer.TRANSLUCENT;
}
@Override
public void onLandedUpon(World world, BlockPos pos, Entity entityIn, float fallDistance) {
if (!applyLanding(entityIn, fallDistance)) {
super.onLandedUpon(world, pos, entityIn, fallDistance);
}
}
@Override
public void onEntityLand(BlockView world, Entity entity) {
if (!applyRebound(entity)) {
super.onEntityLand(world, entity);
}
}
@Override
public boolean canConnect(BlockState state, boolean bool, Direction facing) {
return !(state.getBlock() instanceof CloudBanisterBlock)
&& super.canConnect(state, bool, facing);
}
@Override
public void onEntityCollision(BlockState state, World w, BlockPos pos, Entity entity) {
if (!applyBouncyness(state, entity)) {
super.onEntityCollision(state, w, pos, entity);
}
}
@Deprecated
@Override
public float calcBlockBreakingDelta(BlockState state, PlayerEntity player, BlockView world, BlockPos pos) {
if (CloudType.NORMAL.canInteract(player)) {
return super.calcBlockBreakingDelta(state, player, world, pos);
}
return -1;
}
}

View file

@ -0,0 +1,69 @@
package com.minelittlepony.unicopia.block;
import com.minelittlepony.unicopia.CloudType;
import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.block.StairsBlock;
import net.minecraft.block.enums.SlabType;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.Direction;
public class CloudSlabBlock<T extends Block & ICloudBlock> extends USlab<T> implements ICloudBlock {
public CloudSlabBlock(T modelBlock, Material material) {
super(modelBlock, FabricBlockSettings.of(material).build());
}
@Override
public CloudType getCloudMaterialType(BlockState blockState) {
return modelBlock.getCloudMaterialType(blockState);
}
@Override
public boolean isSideInvisible(BlockState state, BlockState beside, Direction face) {
if (isDouble(state)) {
if (beside.getBlock() instanceof ICloudBlock) {
ICloudBlock cloud = ((ICloudBlock)beside.getBlock());
if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) {
return true;
}
}
return false;
} else {
if (beside.getBlock() instanceof ICloudBlock) {
ICloudBlock cloud = ((ICloudBlock)beside.getBlock());
if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) {
SlabType half = state.get(TYPE);
if (beside.getBlock() instanceof BlockCloudStairs) {
return beside.get(StairsBlock.HALF).ordinal() == state.get(TYPE).ordinal()
&& beside.get(Properties.FACING) == face;
}
if (face == Direction.DOWN) {
return half == SlabType.BOTTOM;
}
if (face == Direction.UP) {
return half == SlabType.TOP;
}
if (beside.getBlock() == this) {
return beside.get(TYPE) == state.get(TYPE);
}
}
}
}
return false;
}
}

View file

@ -0,0 +1,40 @@
package com.minelittlepony.unicopia.block;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.EquinePredicates;
import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.block.MaterialColor;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class DiamondDoorBlock extends AbstractDoorBlock {
public DiamondDoorBlock() {
super(FabricBlockSettings.of(Material.METAL)
.sounds(BlockSoundGroup.METAL)
.materialColor(MaterialColor.DIAMOND)
.hardness(5)
.build());
}
@Override
protected boolean canOpen(@Nullable PlayerEntity player) {
return EquinePredicates.MAGI.test(player);
}
@Override
protected boolean onPowerStateChanged(World world, BlockState state, BlockPos pos, boolean powered) {
if (state.get(OPEN)) {
world.setBlockState(pos, state.with(OPEN, false), 2);
return true;
}
return false;
}
}

View file

@ -0,0 +1,56 @@
package com.minelittlepony.unicopia.block;
import net.minecraft.block.BlockState;
import net.minecraft.block.enums.DoubleBlockHalf;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
public class DutchDoorBlock extends AbstractDoorBlock {
public DutchDoorBlock(Settings settings) {
super(settings);
}
@Override
protected BlockPos getPrimaryDoorPos(BlockState state, BlockPos pos) {
return pos;
}
@Override
protected boolean onPowerStateChanged(World world, BlockState state, BlockPos pos, boolean powered) {
boolean result = super.onPowerStateChanged(world, state, pos, powered);
BlockState upper = world.getBlockState(pos.up());
if (upper.getBlock() == this && upper.get(OPEN) != powered) {
world.setBlockState(pos.up(), upper.with(OPEN, powered));
return true;
}
return result;
}
// UPPER - HALF/HINGE/POWER{/OPEN}
// LOWER - HALF/FACING/FACING/OPEN
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction face, BlockState other, IWorld world, BlockPos pos, BlockPos otherPos) {
// copy properties in stored by the sibling block
if (state.get(HALF) == DoubleBlockHalf.LOWER) {
if (other.getBlock() == this) {
return state.with(HINGE, other.get(HINGE))
.with(POWERED, other.get(POWERED));
}
} else {
if (other.getBlock() == this) {
return state.with(FACING, other.get(FACING));
}
}
return state;
}
}

View file

@ -53,7 +53,7 @@ public class GlowingGemBlock extends TorchBlock implements ICloudBlock {
protected static final VoxelShape TORCH_WEST_AABB = VoxelShapes.cuboid(new Box(F, E, B, 1, 1, C)); protected static final VoxelShape TORCH_WEST_AABB = VoxelShapes.cuboid(new Box(F, E, B, 1, 1, C));
protected static final VoxelShape TORCH_EAST_AABB = VoxelShapes.cuboid(new Box(0, E, B, A, 1, C)); protected static final VoxelShape TORCH_EAST_AABB = VoxelShapes.cuboid(new Box(0, E, B, A, 1, C));
public GlowingGemBlock(String domain, String name) { public GlowingGemBlock() {
super(FabricBlockSettings.of(Material.PART) super(FabricBlockSettings.of(Material.PART)
.noCollision() .noCollision()
.strength(0, 0) .strength(0, 0)

View file

@ -2,7 +2,8 @@ package com.minelittlepony.unicopia.block;
import com.minelittlepony.unicopia.CloudType; import com.minelittlepony.unicopia.CloudType;
import com.minelittlepony.unicopia.EquinePredicates; import com.minelittlepony.unicopia.EquinePredicates;
import com.minelittlepony.unicopia.UClient; import com.minelittlepony.unicopia.InteractionManager;
import net.minecraft.block.BedBlock; import net.minecraft.block.BedBlock;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
@ -25,7 +26,7 @@ public interface ICloudBlock {
default boolean handleRayTraceSpecialCases(World world, BlockPos pos, BlockState state) { default boolean handleRayTraceSpecialCases(World world, BlockPos pos, BlockState state) {
if (world.isClient) { if (world.isClient) {
PlayerEntity player = UClient.instance().getPlayer(); PlayerEntity player = InteractionManager.instance().getClientPlayer();
if (player.abilities.creativeMode) { if (player.abilities.creativeMode) {
return false; return false;

View file

@ -1,13 +0,0 @@
package com.minelittlepony.unicopia.block;
import net.minecraft.block.BlockState;
import net.minecraft.world.World;
@FunctionalInterface
public interface ITreeGen {
WorldGenAbstractTree getTreeGen(World world, BlockState state, boolean massive);
default boolean canGrowMassive() {
return false;
}
}

View file

@ -1,199 +0,0 @@
package com.minelittlepony.unicopia.block;
import java.util.Random;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import com.minelittlepony.util.WorldEvent;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.DoorBlock;
import net.minecraft.block.Material;
import net.minecraft.block.enums.DoubleBlockHalf;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
public abstract class UDoor extends DoorBlock {
private final Supplier<Item> theItem;
protected UDoor(Material material, String domain, String name, Supplier<Item> theItem) {
super(material);
disableStats();
setTranslationKey(name);
setRegistryName(domain, name);
this.theItem = theItem;
}
@Override
public Block setSoundType(SoundType sound) {
return super.setSoundType(sound);
}
@Override
public Item getItemDropped(BlockState state, Random rand, int fortune) {
return state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER ? Items.AIR : getItem();
}
@Override
public ItemStack getItem(World world, BlockPos pos, BlockState state) {
return new ItemStack(getItem());
}
protected Item getItem() {
return theItem.get();
}
protected WorldEvent getCloseSound() {
return isLockable() ? WorldEvent.IRON_DOOR_SLAM : WorldEvent.WOODEN_DOOR_SLAM;
}
protected WorldEvent getOpenSound() {
return isLockable() ? WorldEvent.IRON_DOOR_OPEN : WorldEvent.WOODEN_DOOR_OPEN;
}
@Override
public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
return toggleDoor(world, pos, false, true, player);
}
@Override
public void setOpen(World world, BlockPos pos, boolean open) {
toggleDoor(world, pos, open, false, null);
}
protected boolean isLockable() {
return material == Material.METAL;
}
protected boolean canBePowered() {
return true;
}
protected boolean canOpen(@Nullable PlayerEntity player) {
return player == null || material != Material.METAL;
}
protected boolean toggleDoor(World world, BlockPos pos, boolean open, boolean force, @Nullable PlayerEntity player) {
if (!canOpen(player)) {
return false;
}
BlockState state = world.getBlockState(pos);
if (state.getBlock() != this) {
return false;
}
BlockPos lower = getPrimaryDoorPos(state, pos);
BlockState mainDoor = pos == lower ? state : world.getBlockState(lower);
if (mainDoor.getBlock() != this) {
return false;
}
if (!force && mainDoor.get(OPEN) == open) {
return false;
}
state = mainDoor.cycle(OPEN);
world.setBlockState(lower, state, 10);
world.markBlockRangeForRenderUpdate(lower, pos);
WorldEvent sound = state.getValue(OPEN) ? getOpenSound() : getCloseSound();
world.playEvent(player, sound.getId(), pos, 0);
return true;
}
protected BlockPos getPrimaryDoorPos(BlockState state, BlockPos pos) {
return state.get(HALF) == DoubleBlockHalf.LOWER ? pos : pos.down();
}
@Override
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block sender, BlockPos fromPos, boolean v) {
if (state.get(HALF) == DoubleBlockHalf.UPPER) {
BlockPos lower = pos.down();
BlockState lowerDoor = world.getBlockState(lower);
// pop us off if we don't have a lower door
if (lowerDoor.getBlock() != this) {
world.breakBlock(pos, true);
} else if (sender != this) {
lowerDoor.neighborUpdate(world, lower, sender, fromPos, v);
}
return;
}
boolean destroyed = false;
BlockPos upper = pos.up();
BlockState upperDoor = world.getBlockState(upper);
// pop us off if we don't have an upper door
if (upperDoor.getBlock() != this) {
world.breakBlock(pos, true);
destroyed = true;
}
// pop us off if we don't have support
if (!world.getBlockState(pos.down()).hasSolidTopSurface(world, pos.down(), null)) {
world.breakBlock(pos, true);
destroyed = true;
if (upperDoor.getBlock() == this) {
world.breakBlock(upper, true);
}
}
if (destroyed) {
if (!world.isClient) {
dropBlockAsItem(world, pos, state, 0);
}
} else if (canBePowered()) {
boolean powered = world.isReceivingRedstonePower(pos) || world.isReceivingRedstonePower(upper);
if (sender != this && (powered || sender.getDefaultState().emitsRedstonePower()) && powered != upperDoor.get(POWERED)) {
world.setBlockState(upper, upperDoor.with(POWERED, powered), 2);
if (onPowerStateChanged(world, state, pos, powered)) {
world.markBlockRangeForRenderUpdate(pos, upper);
WorldEvent sound = powered ? getOpenSound() : getCloseSound();
world.playGlobalEvent(null, sound.getId(), pos, 0);
}
}
}
}
/**
* Called by the lower block when the powered state changes.
*/
protected boolean onPowerStateChanged(World world, BlockState state, BlockPos pos, boolean powered) {
if (powered != state.get(OPEN)) {
world.setBlockState(pos, state.with(OPEN, powered), 2);
return true;
}
return false;
}
}

View file

@ -11,9 +11,7 @@ import net.minecraft.world.World;
public class UPot extends FlowerPotBlock { public class UPot extends FlowerPotBlock {
public UPot(String domain, String name) { public UPot() {
setTranslationKey(name);
setRegistryName(domain, name);
setHardness(0); setHardness(0);
setSoundType(SoundType.STONE); setSoundType(SoundType.STONE);
} }

View file

@ -1,159 +0,0 @@
package com.minelittlepony.unicopia.block;
import java.util.Random;
import javax.annotation.Nullable;
import com.minelittlepony.util.LenientState;
import net.minecraft.block.BlockPlanks;
import net.minecraft.block.BlockSapling;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.BlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenAbstractTree;
public class USapling extends BlockSapling implements ITreeGen {
private ITreeGen treeGen;
public USapling(String domain, String name) {
setRegistryName(domain, name);
setTranslationKey(name);
setSoundType(SoundType.PLANT);
setDefaultState(stateFactory.getDefaultState().with(STAGE, 0));
}
public USapling setTreeGen(ITreeGen gen) {
treeGen = gen;
return this;
}
@Override
public void generateTree(World world, BlockPos pos, BlockState state, Random rand) {
boolean massive = canGrowMassive();
BlockPos i = massive ? findTwoByTwoSpace(world, pos, state) : pos;
if (i == null) {
massive = false;
i = BlockPos.ORIGIN;
}
// remove the sapling and any contributing siblings before growing the tree
setSaplingsState(world, Blocks.AIR.getDefaultState(), massive, i);
if (!getTreeGen(world, state, massive).generate(world, rand, i)) {
// place them back if tree growth failed
setSaplingsState(world, state, massive, i);
}
}
@Override
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> items) {
items.add(new ItemStack(this));
}
protected void setSaplingsState(World world, BlockState state, boolean massive, BlockPos pos) {
if (massive) {
world.setBlockState(pos , state, 4);
world.setBlockState(pos.add(1, 0, 0), state, 4);
world.setBlockState(pos.add(0, 0, 1), state, 4);
world.setBlockState(pos.add(1, 0, 1), state, 4);
} else {
world.setBlockState(pos, state, 4);
}
}
@Override
public WorldGenAbstractTree getTreeGen(World world, BlockState state, boolean massive) {
return treeGen.getTreeGen(world, state, massive);
}
@Override
public boolean canGrowMassive() {
return treeGen.canGrowMassive();
}
/**
* Looks for a suitable 2x2 space that a tree can grow in.
* Returns null if no such spaces were found.
*/
@Nullable
public BlockPos findTwoByTwoSpace(World world, BlockPos pos, BlockState state) {
BlockPos xNegP = pos.add(-1, 0, 0);
BlockPos xPosP = pos.add( 1, 0, 0);
BlockPos zNegP = pos.add( 0, 0, -1);
BlockPos zPosP = pos.add( 0, 0, 1);
boolean xNeg = isMatch(state, world.getBlockState(xNegP));
boolean xPos = isMatch(state, world.getBlockState(xPosP));
boolean zNeg = isMatch(state, world.getBlockState(zNegP));
boolean zPos = isMatch(state, world.getBlockState(zPosP));
if (xNeg && zNeg) {
BlockPos corner = pos.add(-1, 0, -1);
if (isMatch(state, world.getBlockState(corner))) {
return corner;
}
}
if (xNeg && zPos && isMatch(state, world.getBlockState(pos.add(-1, 0, 1)))) {
return xNegP;
}
if (xPos && zNeg && isMatch(state, world.getBlockState(pos.add(1, 0, -1)))) {
return pos;
}
if (xPos && zPos && isMatch(state, world.getBlockState(pos.add(-1, 0, 1)))) {
return zNegP;
}
return null;
}
protected boolean isMatch(BlockState state, BlockState other) {
return other.getBlock() == this;
}
@Deprecated
@Override
public boolean isTypeAt(World world, BlockPos pos, BlockPlanks.EnumType type) {
return world.getBlockState(pos).getBlock() == this;
}
@Override
public int damageDropped(BlockState state) {
return 0;
}
@Override
public BlockState getStateFromMeta(int meta) {
return getDefaultState().with(STAGE, (meta & 8) >> 3);
}
@Override
public int getMetaFromState(BlockState state) {
int i = 0;
i |= state.getValue(STAGE) << 3;
return i;
}
@Override
protected BlockStateContainer createBlockState() {
return new LenientState(this, STAGE);
}
}

View file

@ -1,8 +1,8 @@
package com.minelittlepony.unicopia.client; package com.minelittlepony.unicopia.client;
import com.minelittlepony.unicopia.InteractionManager;
import com.minelittlepony.unicopia.SpeciesList; import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.UBlocks; import com.minelittlepony.unicopia.UBlocks;
import com.minelittlepony.unicopia.UClient;
import com.minelittlepony.unicopia.UItems; import com.minelittlepony.unicopia.UItems;
import com.minelittlepony.unicopia.client.gui.UHud; import com.minelittlepony.unicopia.client.gui.UHud;
import com.minelittlepony.unicopia.entity.capabilities.ICamera; import com.minelittlepony.unicopia.entity.capabilities.ICamera;
@ -17,24 +17,24 @@ class ClientHooks {
public static void postEntityRender() { public static void postEntityRender() {
GlStateManager.enableAlphaTest(); GlStateManager.enableAlphaTest();
UClient.instance().postRenderEntity(event.getEntity()); InteractionManager.instance().postRenderEntity(event.getEntity());
} }
public static void preEntityRender() { public static void preEntityRender() {
if (UClient.instance().renderEntity(event.getEntity(), event.getPartialRenderTick())) { if (InteractionManager.instance().renderEntity(event.getEntity(), event.getPartialRenderTick())) {
event.setCanceled(true); event.setCanceled(true);
} }
} }
public static void onDisplayGui(GuiScreenEvent.InitGuiEvent.Post event) { public static void onDisplayGui(GuiScreenEvent.InitGuiEvent.Post event) {
if (event.getGui() instanceof GuiOptions || event.getGui() instanceof GuiShareToLan) { if (event.getGui() instanceof GuiOptions || event.getGui() instanceof GuiShareToLan) {
UnicopiaClient.addUniButton(event.getButtonList()); ClientInteractionManager.addUniButton(event.getButtonList());
} }
} }
public static void onGameTick(TickEvent.ClientTickEvent event) { public static void onGameTick(TickEvent.ClientTickEvent event) {
if (event.phase == Phase.END) { if (event.phase == Phase.END) {
UClient.instance().tick(); InteractionManager.instance().tick();
} }
} }
@ -42,7 +42,7 @@ class ClientHooks {
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();
if (event.getType() != ElementType.ALL) { if (event.getType() != ElementType.ALL) {
IPlayer player = UClient.instance().getIPlayer(); IPlayer player = InteractionManager.instance().getIPlayer();
if (player != null && MinecraftClient.getInstance().world != null) { if (player != null && MinecraftClient.getInstance().world != null) {
UHud.instance.repositionElements(player, event.getResolution(), event.getType(), true); UHud.instance.repositionElements(player, event.getResolution(), event.getType(), true);
@ -59,7 +59,7 @@ class ClientHooks {
public static void postRenderHud(RenderGameOverlayEvent.Post event) { public static void postRenderHud(RenderGameOverlayEvent.Post event) {
if (event.getType() == ElementType.ALL) { if (event.getType() == ElementType.ALL) {
IPlayer player = UClient.instance().getIPlayer(); IPlayer player = InteractionManager.instance().getIPlayer();
if (player != null && MinecraftClient.getInstance().world != null) { if (player != null && MinecraftClient.getInstance().world != null) {
UHud.instance.renderHud(player, event.getResolution()); UHud.instance.renderHud(player, event.getResolution());
@ -80,7 +80,7 @@ class ClientHooks {
public static void setupPlayerCamera(EntityViewRenderEvent.CameraSetup event) { public static void setupPlayerCamera(EntityViewRenderEvent.CameraSetup event) {
IPlayer player = UClient.instance().getIPlayer(); IPlayer player = InteractionManager.instance().getIPlayer();
if (player != null) { if (player != null) {
ICamera view = player.getCamera(); ICamera view = player.getCamera();

View file

@ -9,8 +9,9 @@ import javax.annotation.Nullable;
import com.minelittlepony.unicopia.MineLP; import com.minelittlepony.unicopia.MineLP;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.SpeciesList; import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.UClient; import com.minelittlepony.unicopia.ServerInteractionManager;
import com.minelittlepony.unicopia.Config; import com.minelittlepony.unicopia.Config;
import com.minelittlepony.unicopia.InteractionManager;
import com.minelittlepony.unicopia.UEntities; import com.minelittlepony.unicopia.UEntities;
import com.minelittlepony.unicopia.UParticles; import com.minelittlepony.unicopia.UParticles;
import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.Unicopia;
@ -19,17 +20,22 @@ import com.minelittlepony.unicopia.client.gui.SettingsScreen;
import com.minelittlepony.unicopia.client.input.Keyboard; import com.minelittlepony.unicopia.client.input.Keyboard;
import com.minelittlepony.unicopia.client.input.MouseControl; import com.minelittlepony.unicopia.client.input.MouseControl;
import com.minelittlepony.unicopia.entity.capabilities.IPlayer; import com.minelittlepony.unicopia.entity.capabilities.IPlayer;
import com.minelittlepony.unicopia.inventory.gui.GuiOfHolding;
import com.minelittlepony.unicopia.client.input.InversionAwareKeyboardInput; import com.minelittlepony.unicopia.client.input.InversionAwareKeyboardInput;
import com.minelittlepony.unicopia.network.MsgRequestCapabilities; import com.minelittlepony.unicopia.network.MsgRequestCapabilities;
import com.minelittlepony.util.dummy.DummyClientPlayerEntity;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.input.Input; import net.minecraft.client.input.Input;
import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.container.ContainerType;
import net.minecraft.container.NameableContainerProvider;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
public class UnicopiaClient extends UClient { public class ClientInteractionManager extends ServerInteractionManager {
/** /**
* The race preferred by the client - as determined by mine little pony. * The race preferred by the client - as determined by mine little pony.
@ -55,52 +61,41 @@ public class UnicopiaClient extends UClient {
return Config.instance().getPrefferedRace(); return Config.instance().getPrefferedRace();
} }
@Override
public void displayGuiToPlayer(PlayerEntity player, IInteractionObject inventory) {
if (player instanceof PlayerEntitySP) {
if ("unicopia:itemofholding".equals(inventory.getGuiID())) {
MinecraftClient.getInstance().displayGuiScreen(new GuiOfHolding(inventory));
}
} else {
super.displayGuiToPlayer(player, inventory);
}
}
@Override @Override
@Nullable @Nullable
public PlayerEntity getPlayer() { public PlayerEntity getClientPlayer() {
return MinecraftClient.getInstance().player; return MinecraftClient.getInstance().player;
} }
@Override @Override
@Nullable @Nullable
public PlayerEntity getPlayerByUUID(UUID playerId) { public PlayerEntity getPlayerByUUID(UUID playerId) {
Minecraft mc = MinecraftClient.getInstance(); MinecraftClient mc = MinecraftClient.getInstance();
if (mc.player.getUniqueID().equals(playerId)) { if (mc.player.getUuid().equals(playerId)) {
return mc.player; return mc.player;
} }
return mc.world.getPlayerEntityByUUID(playerId); return mc.world.getPlayerByUuid(playerId);
} }
@Override @Override
@Nonnull @Nonnull
public PlayerEntity createPlayer(Entity observer, GameProfile profile) { public PlayerEntity createPlayer(Entity observer, GameProfile profile) {
return new EntityFakeClientPlayer(observer.world, profile); return new DummyClientPlayerEntity(observer.world, profile);
} }
@Override @Override
public boolean isClientPlayer(@Nullable PlayerEntity player) { public boolean isClientPlayer(@Nullable PlayerEntity player) {
if (getPlayer() == player) { if (getClientPlayer() == player) {
return true; return true;
} }
if (getPlayer() == null || player == null) { if (getClientPlayer() == null || player == null) {
return false; return false;
} }
return IPlayer.equal(getPlayer(), player); return IPlayer.equal(getClientPlayer(), player);
} }
@Override @Override
@ -115,9 +110,9 @@ public class UnicopiaClient extends UClient {
if (iplayer.getGravity().getGravitationConstant() < 0) { if (iplayer.getGravity().getGravitationConstant() < 0) {
GlStateManager.translate(0, entity.height, 0); GlStateManager.translate(0, entity.height, 0);
GlStateManager.scale(1, -1, 1); GlStateManager.scalef(1, -1, 1);
entity.prevRotationPitch *= -1; entity.prevPitch *= -1;
entity.rotationPitch *= -1; entity.pitch *= -1;
} }
} }
} }
@ -133,10 +128,10 @@ public class UnicopiaClient extends UClient {
IPlayer iplayer = SpeciesList.instance().getPlayer((PlayerEntity)entity); IPlayer iplayer = SpeciesList.instance().getPlayer((PlayerEntity)entity);
if (iplayer.getGravity().getGravitationConstant() < 0) { if (iplayer.getGravity().getGravitationConstant() < 0) {
GlStateManager.scale(1, -1, 1); GlStateManager.scalef(1, -1, 1);
GlStateManager.translate(0, -entity.height, 0); GlStateManager.translate(0, -entity.height, 0);
entity.prevRotationPitch *= -1; entity.prevPitch *= -1;
entity.rotationPitch *= -1; entity.pitch *= -1;
} }
if (DisguiseRenderer.getInstance().renderDisguiseToGui(iplayer)) { if (DisguiseRenderer.getInstance().renderDisguiseToGui(iplayer)) {
@ -164,7 +159,7 @@ public class UnicopiaClient extends UClient {
@Override @Override
public void tick() { public void tick() {
PlayerEntity player = UClient.instance().getPlayer(); PlayerEntity player = InteractionManager.instance().getClientPlayer();
if (player != null && !player.removed) { if (player != null && !player.removed) {
Race newRace = getclientPlayerRace(); Race newRace = getclientPlayerRace();

View file

@ -1,22 +0,0 @@
package com.minelittlepony.unicopia.client;
import com.minelittlepony.unicopia.client.particle.ParticleChangelingMagic;
import com.minelittlepony.unicopia.client.particle.ParticleDisk;
import com.minelittlepony.unicopia.client.particle.ParticleRaindrops;
import com.minelittlepony.unicopia.client.particle.ParticleSphere;
import com.minelittlepony.unicopia.client.particle.ParticleUnicornMagic;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.particle.DefaultParticleType;
import net.minecraft.util.Identifier;
class UParticles extends com.minelittlepony.unicopia.UParticles {
static void bootstrap() {
ParticleFactoryRegistry.instance().register(UNICORN_MAGIC, ParticleUnicornMagic::new);
ParticleFactoryRegistry.instance().register(CHANGELING_MAGIC, ParticleChangelingMagic::new);
ParticleFactoryRegistry.instance().register(RAIN_DROPS, ParticleRaindrops::new);
ParticleFactoryRegistry.instance().register(SPHERE, ParticleSphere::new);
ParticleFactoryRegistry.instance().register(DISK, ParticleDisk::new);
}
}

View file

@ -1,5 +1,11 @@
package com.minelittlepony.unicopia.client; package com.minelittlepony.unicopia.client;
import com.minelittlepony.unicopia.UParticles;
import com.minelittlepony.unicopia.client.particle.ParticleChangelingMagic;
import com.minelittlepony.unicopia.client.particle.ParticleDisk;
import com.minelittlepony.unicopia.client.particle.ParticleRaindrops;
import com.minelittlepony.unicopia.client.particle.ParticleSphere;
import com.minelittlepony.unicopia.client.particle.ParticleUnicornMagic;
import com.minelittlepony.unicopia.client.render.entity.ButterflyEntityRenderer; import com.minelittlepony.unicopia.client.render.entity.ButterflyEntityRenderer;
import com.minelittlepony.unicopia.client.render.entity.RenderCloud; import com.minelittlepony.unicopia.client.render.entity.RenderCloud;
import com.minelittlepony.unicopia.client.render.entity.RenderCuccoon; import com.minelittlepony.unicopia.client.render.entity.RenderCuccoon;
@ -7,11 +13,11 @@ import com.minelittlepony.unicopia.client.render.entity.RenderRainbow;
import com.minelittlepony.unicopia.client.render.entity.RenderSpear; import com.minelittlepony.unicopia.client.render.entity.RenderSpear;
import com.minelittlepony.unicopia.client.render.entity.RenderSpellbook; import com.minelittlepony.unicopia.client.render.entity.RenderSpellbook;
import com.minelittlepony.unicopia.client.render.entity.SpellcastEntityRenderer; import com.minelittlepony.unicopia.client.render.entity.SpellcastEntityRenderer;
import com.minelittlepony.unicopia.entity.AdvancedProjectileEntity; import com.minelittlepony.unicopia.entity.ProjectileEntity;
import com.minelittlepony.unicopia.entity.ButterflyEntity; import com.minelittlepony.unicopia.entity.ButterflyEntity;
import com.minelittlepony.unicopia.entity.CloudEntity; import com.minelittlepony.unicopia.entity.CloudEntity;
import com.minelittlepony.unicopia.entity.EntityCuccoon; import com.minelittlepony.unicopia.entity.CuccoonEntity;
import com.minelittlepony.unicopia.entity.EntitySpear; import com.minelittlepony.unicopia.entity.SpearEntity;
import com.minelittlepony.unicopia.entity.RainbowEntity; import com.minelittlepony.unicopia.entity.RainbowEntity;
import com.minelittlepony.unicopia.entity.SpellbookEntity; import com.minelittlepony.unicopia.entity.SpellbookEntity;
import com.minelittlepony.unicopia.entity.SpellcastEntity; import com.minelittlepony.unicopia.entity.SpellcastEntity;
@ -31,15 +37,21 @@ import net.minecraft.world.biome.OceanBiome;
import net.minecraft.world.biome.PlainsBiome; import net.minecraft.world.biome.PlainsBiome;
import net.minecraft.world.biome.RiverBiome; import net.minecraft.world.biome.RiverBiome;
public class UEntityRenderers { public class URenderers {
static void bootstrap() { static void bootstrap() {
EntityRendererRegistry.INSTANCE.register(CloudEntity.class, RenderCloud::new); EntityRendererRegistry.INSTANCE.register(CloudEntity.class, RenderCloud::new);
EntityRendererRegistry.INSTANCE.register(SpellcastEntity.class, SpellcastEntityRenderer::new); EntityRendererRegistry.INSTANCE.register(SpellcastEntity.class, SpellcastEntityRenderer::new);
EntityRendererRegistry.INSTANCE.register(AdvancedProjectileEntity.class, (manager, context) -> new FlyingItemEntityRenderer<>(manager, MinecraftClient.getInstance().getItemRenderer())); EntityRendererRegistry.INSTANCE.register(ProjectileEntity.class, (manager, context) -> new FlyingItemEntityRenderer<>(manager, MinecraftClient.getInstance().getItemRenderer()));
EntityRendererRegistry.INSTANCE.register(SpellbookEntity.class, RenderSpellbook::new); EntityRendererRegistry.INSTANCE.register(SpellbookEntity.class, RenderSpellbook::new);
EntityRendererRegistry.INSTANCE.register(RainbowEntity.class, RenderRainbow::new); EntityRendererRegistry.INSTANCE.register(RainbowEntity.class, RenderRainbow::new);
EntityRendererRegistry.INSTANCE.register(ButterflyEntity.class, ButterflyEntityRenderer::new); EntityRendererRegistry.INSTANCE.register(ButterflyEntity.class, ButterflyEntityRenderer::new);
EntityRendererRegistry.INSTANCE.register(EntityCuccoon.class, RenderCuccoon::new); EntityRendererRegistry.INSTANCE.register(CuccoonEntity.class, RenderCuccoon::new);
EntityRendererRegistry.INSTANCE.register(EntitySpear.class, RenderSpear::new); EntityRendererRegistry.INSTANCE.register(SpearEntity.class, RenderSpear::new);
ParticleFactoryRegistry.instance().register(UParticles.UNICORN_MAGIC, ParticleUnicornMagic::new);
ParticleFactoryRegistry.instance().register(UParticles.CHANGELING_MAGIC, ParticleChangelingMagic::new);
ParticleFactoryRegistry.instance().register(UParticles.RAIN_DROPS, ParticleRaindrops::new);
ParticleFactoryRegistry.instance().register(UParticles.SPHERE, ParticleSphere::new);
ParticleFactoryRegistry.instance().register(UParticles.DISK, ParticleDisk::new);
} }
} }

View file

@ -1,6 +1,6 @@
package com.minelittlepony.unicopia.client.input; package com.minelittlepony.unicopia.client.input;
import com.minelittlepony.unicopia.UClient; import com.minelittlepony.unicopia.InteractionManager;
import com.minelittlepony.unicopia.entity.capabilities.IPlayer; import com.minelittlepony.unicopia.entity.capabilities.IPlayer;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
@ -40,7 +40,7 @@ public class InversionAwareKeyboardInput extends KeyboardInput {
this.movementSideways = proxy.movementSideways; this.movementSideways = proxy.movementSideways;
this.movementForward = proxy.movementForward; this.movementForward = proxy.movementForward;
IPlayer player = UClient.instance().getIPlayer(); IPlayer player = InteractionManager.instance().getIPlayer();
if (player.getGravity().getGravitationConstant() < 0) { if (player.getGravity().getGravitationConstant() < 0) {
boolean tmp = pressingLeft; boolean tmp = pressingLeft;

View file

@ -1,6 +1,6 @@
package com.minelittlepony.unicopia.client.input; package com.minelittlepony.unicopia.client.input;
import com.minelittlepony.unicopia.UClient; import com.minelittlepony.unicopia.ServerInteractionManager;
public final class Keyboard { public final class Keyboard {
private static IKeyBindingHandler keyHandler; private static IKeyBindingHandler keyHandler;
@ -8,7 +8,7 @@ public final class Keyboard {
public static IKeyBindingHandler getKeyHandler() { public static IKeyBindingHandler getKeyHandler() {
if (keyHandler == null) { if (keyHandler == null) {
if (UClient.isClientSide()) { if (ServerInteractionManager.isClientSide()) {
keyHandler = new KeyBindingsHandler(); keyHandler = new KeyBindingsHandler();
} else { } else {
keyHandler = bind -> {}; keyHandler = bind -> {};

View file

@ -1,6 +1,6 @@
package com.minelittlepony.unicopia.client.input; package com.minelittlepony.unicopia.client.input;
import com.minelittlepony.unicopia.UClient; import com.minelittlepony.unicopia.InteractionManager;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.Mouse; import net.minecraft.client.Mouse;
@ -13,7 +13,7 @@ public class MouseControl extends Mouse {
@Override @Override
public void updateMouse() { public void updateMouse() {
if (UClient.instance().getIPlayer().getGravity().getGravitationConstant() < 0) { if (InteractionManager.instance().getIPlayer().getGravity().getGravitationConstant() < 0) {
//cursorDeltaX = -cursorDeltaX; //cursorDeltaX = -cursorDeltaX;
//cursorDeltaY = -cursorDeltaY; //cursorDeltaY = -cursorDeltaY;
} }

View file

@ -12,7 +12,7 @@ public class ParticleChangelingMagic extends PortalParticle {
private int baseTextureIndex = 128; private int baseTextureIndex = 128;
public ParticleChangelingMagic(ParticleEffect type, World world, double x, double y, double z, double dx, double dy, double dz) { public ParticleChangelingMagic(World world, double x, double y, double z, double dx, double dy, double dz) {
super(world, x, y, z, dx, dy, dz); super(world, x, y, z, dx, dy, dz);
float intensity = rand.nextFloat() * 0.6F + 0.4F; float intensity = rand.nextFloat() * 0.6F + 0.4F;

View file

@ -1,9 +1,9 @@
package com.minelittlepony.unicopia.client.render.entity; package com.minelittlepony.unicopia.client.render.entity;
import com.minelittlepony.unicopia.UClient; import com.minelittlepony.unicopia.InteractionManager;
import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.client.render.entity.model.ModelCuccoon; import com.minelittlepony.unicopia.client.render.entity.model.ModelCuccoon;
import com.minelittlepony.unicopia.entity.EntityCuccoon; import com.minelittlepony.unicopia.entity.CuccoonEntity;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
@ -12,7 +12,7 @@ import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
public class RenderCuccoon extends RenderLivingBase<EntityCuccoon> { public class RenderCuccoon extends RenderLivingBase<CuccoonEntity> {
private static final Identifier TEXTURE = new Identifier(Unicopia.MODID, "textures/entity/cuccoon.png"); private static final Identifier TEXTURE = new Identifier(Unicopia.MODID, "textures/entity/cuccoon.png");
@ -21,22 +21,22 @@ public class RenderCuccoon extends RenderLivingBase<EntityCuccoon> {
} }
@Override @Override
protected Identifier getEntityTexture(EntityCuccoon entity) { protected Identifier getEntityTexture(CuccoonEntity entity) {
return TEXTURE; return TEXTURE;
} }
@Override @Override
protected float getDeathMaxRotation(EntityCuccoon entity) { protected float getDeathMaxRotation(CuccoonEntity entity) {
return 0; return 0;
} }
@Override @Override
public void doRender(EntityCuccoon entity, double x, double y, double z, float entityYaw, float partialTicks) { public void doRender(CuccoonEntity entity, double x, double y, double z, float entityYaw, float partialTicks) {
if (entity.isBeingRidden()) { if (entity.isBeingRidden()) {
Entity rider = entity.getPassengers().get(0); Entity rider = entity.getPassengers().get(0);
if (!(rider == MinecraftClient.instance().player) || UClient.instance().getViewMode() != 0) { if (!(rider == MinecraftClient.instance().player) || InteractionManager.instance().getViewMode() != 0) {
GlStateManager.enableAlpha(); GlStateManager.enableAlpha();
GlStateManager.enableBlend(); GlStateManager.enableBlend();

View file

@ -1,13 +1,13 @@
package com.minelittlepony.unicopia.client.render.entity; package com.minelittlepony.unicopia.client.render.entity;
import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.entity.EntitySpear; import com.minelittlepony.unicopia.entity.SpearEntity;
import net.minecraft.client.renderer.entity.RenderArrow; import net.minecraft.client.renderer.entity.RenderArrow;
import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
public class RenderSpear extends RenderArrow<EntitySpear> { public class RenderSpear extends RenderArrow<SpearEntity> {
public static final Identifier TEXTURE = new Identifier(Unicopia.MODID, "textures/entity/projectiles/spear.png"); public static final Identifier TEXTURE = new Identifier(Unicopia.MODID, "textures/entity/projectiles/spear.png");
public RenderSpear(RenderManager manager) { public RenderSpear(RenderManager manager) {
@ -15,7 +15,7 @@ public class RenderSpear extends RenderArrow<EntitySpear> {
} }
@Override @Override
protected Identifier getEntityTexture(EntitySpear entity) { protected Identifier getEntityTexture(SpearEntity entity) {
return TEXTURE; return TEXTURE;
} }
} }

View file

@ -1,6 +1,6 @@
package com.minelittlepony.unicopia.client.render.entity.model; package com.minelittlepony.unicopia.client.render.entity.model;
import com.minelittlepony.unicopia.entity.EntityCuccoon; import com.minelittlepony.unicopia.entity.CuccoonEntity;
import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer; import net.minecraft.client.model.ModelRenderer;
@ -40,7 +40,7 @@ public class ModelCuccoon extends ModelBase {
@Override @Override
public void render(Entity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) { public void render(Entity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
float breatheAmount = ((EntityCuccoon)entity).getBreatheAmount(ageInTicks) / 8; float breatheAmount = ((CuccoonEntity)entity).getBreatheAmount(ageInTicks) / 8;
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();

View file

@ -1,103 +0,0 @@
package com.minelittlepony.unicopia.command;
import java.util.List;
import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.entity.capabilities.IPlayer;
import com.minelittlepony.unicopia.magic.spells.SpellDisguise;
import net.minecraft.command.CommandException;
import net.minecraft.entity.Entity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
class CommandDisguise extends Command {
@Override
public String getName() {
return "disguise";
}
@Override
public int getRequiredPermissionLevel() {
return 2;
}
@Override
public String getUsage(ICommandSender sender) {
return "commands.disguise.usage";
}
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length < 2) {
throw new WrongUsageException(getUsage(sender));
}
ServerPlayerEntity player = args.length > 1 ? getPlayer(server, sender, args[0]) : getCommandSenderAsPlayer(sender);
IPlayer iplayer = SpeciesList.instance().getPlayer(player);
Entity entity = constructDisguiseEntity(player.world, args);
if (entity == null) {
throw new CommandException("commands.disguise.notfound", args[1]);
}
SpellDisguise effect = iplayer.getEffect(SpellDisguise.class, true);
if (effect == null) {
iplayer.setEffect(new SpellDisguise().setDisguise(entity));
} else {
effect.setDisguise(entity);
}
if (player != sender) {
notifyCommandListener(sender, this, 1, "commands.disguise.success.other", player.getName(), entity.getName());
} else {
if (player.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback")) {
player.sendMessage(new TextComponentTranslation("commands.disguise.success.self", entity.getName()));
}
notifyCommandListener(sender, this, 1, "commands.disguise.success.otherself", player.getName(), entity.getName());
}
}
protected Entity constructDisguiseEntity(World world, String[] args) throws CommandException {
CompoundTag nbt = getEntityNBT(args);
nbt.setString("id", args[1]);
return AnvilChunkLoader.readWorldEntityPos(nbt, world, 0, 0, 0, false);
}
protected CompoundTag getEntityNBT(String[] args) throws CommandException {
if (args.length > 2) {
try {
return JsonToNBT.getTagFromJson(buildString(args, 2));
} catch (NBTException e) {
throw new CommandException("commands.summon.tagError", e.getMessage());
}
}
return new CompoundTag();
}
@Override
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) {
if (args.length == 1) {
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
}
if (args.length == 2) {
return getListOfStringsMatchingLastWord(args, EntityList.getEntityNameList());
}
return null;
}
@Override
public boolean isUsernameIndex(String[] args, int index) {
return index == 1;
}
}

View file

@ -1,84 +0,0 @@
package com.minelittlepony.unicopia.command;
import java.util.List;
import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.entity.capabilities.IPlayer;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
class CommandGravity extends CommandBase {
public String getName() {
return "gravity";
}
public int getRequiredPermissionLevel() {
return 4;
}
public String getUsage(ICommandSender sender) {
return "commands.gravity.usage";
}
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length < 2) {
throw new WrongUsageException(getUsage(sender));
}
PlayerEntity player = getCommandSenderAsPlayer(sender);
IPlayer iplayer = SpeciesList.instance().getPlayer(player);
if (args[0].contentEquals("get")) {
String translationKey = "commands.gravity.get";
float gravity = iplayer.getGravity().getGravitationConstant();
if (sender == player) {
player.sendMessage(new TextComponentTranslation(translationKey, gravity));
}
notifyCommandListener(sender, this, 1, translationKey + ".other", player.getName(), gravity);
} else if (args[0].contentEquals("set") || args.length > 2) {
String translationKey = "commands.gravity.set";
float gravity = Float.valueOf(args[2]);
iplayer.getGravity().setGraviationConstant(gravity);
iplayer.sendCapabilities(true);
if (sender == player) {
player.sendMessage(new TextComponentTranslation(translationKey, gravity));
}
notifyCommandListener(sender, this, 1, translationKey + ".other", player.getName(), gravity);
} else {
throw new WrongUsageException(getUsage(sender));
}
}
/**
* Adds the strings available in this command to the given list of tab completion options.
*/
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) {
if (args.length == 1) {
return getListOfStringsMatchingLastWord(args, "get", "set");
}
if (args.length == 2) {
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
}
return null;
}
}

View file

@ -1,51 +0,0 @@
package com.minelittlepony.unicopia.command;
import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.entity.capabilities.IPlayer;
import net.minecraft.command.CommandException;
import net.minecraft.command.CommandGameMode;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.GameType;
class CommandOverrideGameMode extends CommandGameMode {
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] params) throws CommandException {
if (params.length <= 0) {
throw new WrongUsageException("commands.gamemode.usage");
}
GameType gametype = getGameModeFromCommand(sender, params[0]);
PlayerEntity player = params.length >= 2 ? getPlayer(server, sender, params[1]) : getCommandSenderAsPlayer(sender);
updateGameMode(player, gametype);
ITextComponent mode = new TextComponentTranslation("gameMode." + gametype.getName(), new Object[0]);
if (sender.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback")) {
player.sendMessage(new TextComponentTranslation("gameMode.changed", mode));
}
if (player == sender) {
notifyCommandListener(sender, this, 1, "commands.gamemode.success.self", mode);
} else {
notifyCommandListener(sender, this, 1, "commands.gamemode.success.other", player.getName(), mode);
}
}
protected void updateGameMode(PlayerEntity player, GameType m) {
player.setGameType(m);
IPlayer iplayer = SpeciesList.instance().getPlayer(player);
iplayer.setSpecies(iplayer.getSpecies());
}
}

View file

@ -1,100 +0,0 @@
package com.minelittlepony.unicopia.command;
import java.util.ArrayList;
import java.util.List;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.SpeciesList;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextFormatting;
class CommandRacelist extends CommandBase {
public String getName() {
return "racelist";
}
public int getRequiredPermissionLevel() {
return 4;
}
public String getUsage(ICommandSender sender) {
return "commands.racelist.usage";
}
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length < 2) {
throw new WrongUsageException(getUsage(sender));
}
PlayerEntity player = getCommandSenderAsPlayer(sender);
Race race = Race.fromName(args[1], Race.EARTH);
TextComponentTranslation formattedName = new TextComponentTranslation(race.name().toLowerCase());
formattedName.getStyle().setColor(TextFormatting.GOLD);
if (race.isDefault()) {
player.sendMessage(new TextComponentTranslation("commands.racelist.illegal", formattedName));
} else if (args[0].contentEquals("allow")) {
String translationKey = "commands.racelist.allowed";
if (!SpeciesList.instance().whiteListRace(race)) {
translationKey += ".failed";
}
if (sender == player) {
ITextComponent comp = new TextComponentTranslation(translationKey, formattedName);
comp.getStyle().setColor(TextFormatting.GREEN);
player.sendMessage(comp);
}
notifyCommandListener(sender, this, 1, translationKey + ".other", player.getName(), formattedName);
} else if (args[0].contentEquals("disallow")) {
String translationKey = "commands.racelist.disallowed";
if (!SpeciesList.instance().unwhiteListRace(race)) {
translationKey += ".failed";
}
if (sender == player) {
ITextComponent comp = new TextComponentTranslation(translationKey, formattedName);
comp.getStyle().setColor(TextFormatting.GREEN);
player.sendMessage(comp);
}
notifyCommandListener(sender, this, 1, translationKey + ".other", player.getName(), formattedName);
} else {
throw new WrongUsageException(getUsage(sender));
}
}
/**
* Adds the strings available in this command to the given list of tab completion options.
*/
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) {
if (args.length == 1) {
return getListOfStringsMatchingLastWord(args, "allow", "disallow");
}
if (args.length == 2) {
ArrayList<String> names = new ArrayList<String>();
for (Race i : Race.values()) {
names.add(i.name().toLowerCase());
}
return getListOfStringsMatchingLastWord(args, names.stream().toArray(String[]::new));
}
return null;
}
}

View file

@ -1,213 +0,0 @@
package com.minelittlepony.unicopia.command;
import java.util.ArrayList;
import java.util.List;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.SpeciesList;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextFormatting;
class CommandSpecies extends CommandBase {
@Override
public String getName() {
return "race";
}
@Override
public int getRequiredPermissionLevel() {
return 0;
}
@Override
public boolean checkPermission(MinecraftServer server, ICommandSender sender) {
return sender.canUseCommand(getRequiredPermissionLevel(), "help");
}
@Override
public String getUsage(ICommandSender sender) {
return "commands.race.usage";
}
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (!processCommand(server, sender, args)) {
throw new WrongUsageException(getUsage(sender));
}
}
protected boolean processCommand(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length < 1) {
return false;
}
int playerIndex = this.getPlayerIndex(args);
ServerPlayerEntity player = args.length > playerIndex ? getPlayer(server, sender, args[playerIndex]) : getCommandSenderAsPlayer(sender);
if (args.length >= 2) {
switch (args[0]) {
case "set": return updateSpecies(sender, player, args);
case "describe": return describeSpecies(player, args);
}
}
switch (args[0]) {
case "get": return printSpecies(sender, player);
case "list": return list(player);
}
return false;
}
protected int getPlayerIndex(String[] args) {
switch (args[0]) {
case "set":
case "describe": return 2;
default: return 1;
}
}
protected boolean updateSpecies(ICommandSender sender, PlayerEntity player, String[] args) {
Race species = Race.fromName(args[1], Race.HUMAN);
if (species.isDefault()) {
if (player.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback")) {
ITextComponent message = new TextComponentTranslation("commands.race.fail", args[1].toUpperCase());
message.getStyle().setColor(TextFormatting.RED);
player.sendMessage(message);
}
} else if (SpeciesList.instance().speciesPermitted(species, player)) {
SpeciesList.instance().getPlayer(player).setSpecies(species);
ITextComponent formattedName = new TextComponentTranslation(species.name().toLowerCase());
if (player != sender) {
notifyCommandListener(sender, this, 1, "commands.race.success.other", player.getName(), formattedName);
} else {
if (player.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback")) {
player.sendMessage(new TextComponentTranslation("commands.race.success.self"));
}
notifyCommandListener(sender, this, 1, "commands.race.success.otherself", player.getName(), formattedName);
}
} else if (player.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback")) {
player.sendMessage(new TextComponentTranslation("commands.race.permission"));
}
return true;
}
protected boolean printSpecies(ICommandSender sender, PlayerEntity player) {
Race spec = SpeciesList.instance().getPlayer(player).getSpecies();
String name = "commands.race.tell.";
name += player == sender ? "self" : "other";
ITextComponent race = new TextComponentTranslation(spec.getTranslationKey());
ITextComponent message = new TextComponentTranslation(name);
race.getStyle().setColor(TextFormatting.GOLD);
message.appendSibling(race);
player.sendMessage(message);
return true;
}
protected boolean list(PlayerEntity player) {
player.sendMessage(new TextComponentTranslation("commands.race.list"));
ITextComponent message = new TextComponentString("");
boolean first = true;
for (Race i : Race.values()) {
if (!i.isDefault() && SpeciesList.instance().speciesPermitted(i, player)) {
message.appendSibling(new TextComponentString((!first ? "\n" : "") + " - " + i.name().toLowerCase()));
first = false;
}
}
message.getStyle().setColor(TextFormatting.GOLD);
player.sendMessage(message);
return true;
}
protected boolean describeSpecies(PlayerEntity player, String[] args) {
Race species = Race.fromName(args[1], null);
if (species == null) {
if (player.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback")) {
player.sendMessage(new TextComponentTranslation("commands.race.fail", args[1].toUpperCase()));
}
} else {
String name = species.name().toLowerCase();
ITextComponent line1 = new TextComponentTranslation(String.format("commands.race.describe.%s.1", name));
line1.getStyle().setColor(TextFormatting.YELLOW);
player.sendMessage(line1);
player.sendMessage(new TextComponentTranslation(String.format("commands.race.describe.%s.2", name)));
ITextComponent line3 = new TextComponentTranslation(String.format("commands.race.describe.%s.3", name));
line3.getStyle().setColor(TextFormatting.RED);
player.sendMessage(line3);
}
return true;
}
/**
* Adds the strings available in this command to the given list of tab completion options.
*/
@Override
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) {
if (args.length == 1) {
return getListOfStringsMatchingLastWord(args, "get", "set", "list", "describe");
}
if (args.length == 2 && (args[0].contentEquals("set") || args[0].contentEquals("describe"))) {
ArrayList<String> names = new ArrayList<String>();
PlayerEntity player = sender instanceof PlayerEntity ? (PlayerEntity)sender : null;
for (Race i : Race.values()) {
if (args[0].contentEquals("describe") || (!i.isDefault() && SpeciesList.instance().speciesPermitted(i, player))) {
names.add(i.name().toLowerCase());
}
}
return getListOfStringsMatchingLastWord(args, names.stream().toArray(String[]::new));
}
if ((args.length == 3 && args[0].contentEquals("set")) || (args[0].contentEquals("get") && args.length == 2)) {
return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames());
}
return null;
}
@Override
public boolean isUsernameIndex(String[] args, int index) {
return index == getPlayerIndex(args);
}
}

View file

@ -1,13 +1,15 @@
package com.minelittlepony.unicopia.command; package com.minelittlepony.unicopia.command;
import net.fabricmc.fabric.api.registry.CommandRegistry;
public class Commands { public class Commands {
public static void bootstrap() { public static void bootstrap() {
event.registerServerCommand(new CommandOverrideGameMode()); CommandRegistry.INSTANCE.register(false, SpeciesCommand::register);
event.registerServerCommand(new CommandSpecies()); CommandRegistry.INSTANCE.register(false, RacelistCommand::register);
event.registerServerCommand(new CommandRacelist()); CommandRegistry.INSTANCE.register(false, DisguiseCommand::register);
event.registerServerCommand(new CommandDisguise()); CommandRegistry.INSTANCE.register(false, GravityCommand::register);
event.registerServerCommand(new CommandGravity());
event.getServer().setAllowFlight(true); // TODO:
//event.getServer().setAllowFlight(true);
} }
} }

View file

@ -0,0 +1,96 @@
package com.minelittlepony.unicopia.command;
import java.util.function.Function;
import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.entity.capabilities.IPlayer;
import com.minelittlepony.unicopia.magic.spells.SpellDisguise;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import net.minecraft.command.arguments.EntitySummonArgumentType;
import net.minecraft.command.arguments.NbtCompoundTagArgumentType;
import net.minecraft.command.suggestion.SuggestionProviders;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
import net.minecraft.world.GameRules;
class DisguiseCommand {
private static final SimpleCommandExceptionType FAILED_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("commands.disguise.notfound"));
static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
LiteralArgumentBuilder<ServerCommandSource> builder = CommandManager
.literal("disguise")
.requires(s -> s.hasPermissionLevel(2))
.executes(context -> reveal(context.getSource(), context.getSource().getPlayer()));
builder.then(CommandManager
.argument("entity", EntitySummonArgumentType.entitySummon())
.suggests(SuggestionProviders.SUMMONABLE_ENTITIES)
.executes(context -> disguise(context.getSource(),
context.getSource().getPlayer(),
EntitySummonArgumentType.getEntitySummon(context, "entity"),
new CompoundTag(), true))
.then(CommandManager.argument("nbt", NbtCompoundTagArgumentType.nbtCompound())
.executes(context -> disguise(context.getSource(),
context.getSource().getPlayer(),
EntitySummonArgumentType.getEntitySummon(context, "entity"),
NbtCompoundTagArgumentType.getCompoundTag(context, "nbt"), false))
));
dispatcher.register(builder);
}
static int disguise(ServerCommandSource source, PlayerEntity player, Identifier id, CompoundTag nbt, boolean isSelf) throws CommandSyntaxException {
nbt = nbt.method_10553();
nbt.putString("id", id.toString());
IPlayer iplayer = SpeciesList.instance().getPlayer(player);
Entity entity = EntityType.loadEntityWithPassengers(nbt, source.getWorld(), Function.identity());
if (entity == null) {
throw FAILED_EXCEPTION.create();
}
SpellDisguise effect = iplayer.getEffect(SpellDisguise.class, true);
if (effect == null) {
iplayer.setEffect(new SpellDisguise().setDisguise(entity));
} else {
effect.setDisguise(entity);
}
if (!isSelf) {
source.sendFeedback(new TranslatableText("commands.disguise.success.other", player.getName(), entity.getName()), true);
} else {
if (player.getEntityWorld().getGameRules().getBoolean(GameRules.SEND_COMMAND_FEEDBACK)) {
player.sendMessage(new TranslatableText("commands.disguise.success.self", entity.getName()));
}
source.sendFeedback(new TranslatableText("commands.disguise.success.otherself", player.getName(), entity.getName()), true);
}
return 0;
}
static int reveal(ServerCommandSource source, PlayerEntity player) {
IPlayer iplayer = SpeciesList.instance().getPlayer(player);
iplayer.getEffect(SpellDisguise.class).ifPresent(disguise -> {
disguise.setDead();
});
if (player.getEntityWorld().getGameRules().getBoolean(GameRules.SEND_COMMAND_FEEDBACK)) {
player.sendMessage(new TranslatableText("commands.disguise.removed"));
}
return 0;
}
}

View file

@ -0,0 +1,69 @@
package com.minelittlepony.unicopia.command;
import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.entity.capabilities.IPlayer;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.FloatArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.command.arguments.EntityArgumentType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.TranslatableText;
class GravityCommand {
static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
LiteralArgumentBuilder<ServerCommandSource> builder = CommandManager.literal("gravity").requires(s -> s.hasPermissionLevel(4));
builder.then(CommandManager
.literal("get")
.executes(context -> get(context.getSource(), context.getSource().getPlayer(), true))
).then(CommandManager.argument("target", EntityArgumentType.player())
.executes(context -> get(context.getSource(), EntityArgumentType.getPlayer(context, "target"), false))
);
builder.then(CommandManager
.literal("set")
.then(CommandManager.argument("gravity", FloatArgumentType.floatArg(-99, 99))
.executes(context -> set(context.getSource(), context.getSource().getPlayer(), FloatArgumentType.getFloat(context, "gravity"), true))
.then(CommandManager.argument("target", EntityArgumentType.player())
.executes(context -> set(context.getSource(), EntityArgumentType.getPlayer(context, "target"), FloatArgumentType.getFloat(context, "gravity"), false))
)));
dispatcher.register(builder);
}
static int get(ServerCommandSource source, PlayerEntity player, boolean isSelf) {
String translationKey = "commands.gravity.get";
IPlayer iplayer = SpeciesList.instance().getPlayer(player);
float gravity = iplayer.getGravity().getGravitationConstant();
if (isSelf) {
player.sendMessage(new TranslatableText(translationKey, gravity));
}
source.sendFeedback(new TranslatableText(translationKey + ".other", player.getName(), gravity), true);
return 0;
}
static int set(ServerCommandSource source, PlayerEntity player, float gravity, boolean isSelf) {
String translationKey = "commands.gravity.set";
IPlayer iplayer = SpeciesList.instance().getPlayer(player);
iplayer.getGravity().setGraviationConstant(gravity);
iplayer.sendCapabilities(true);
if (isSelf) {
player.sendMessage(new TranslatableText(translationKey, gravity));
}
source.sendFeedback(new TranslatableText(translationKey + ".other", player.getName(), gravity), true);
return 0;
}
}

View file

@ -0,0 +1,27 @@
package com.minelittlepony.unicopia.command;
import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Collectors;
import com.minelittlepony.unicopia.Race;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
class RaceArgument implements ArgumentType<Race> {
static final Collection<String> EXAMPLES = Arrays.stream(Race.values())
.filter(Race::isUsable)
.map(Race::name)
.collect(Collectors.toList());
@Override
public Race parse(StringReader reader) throws CommandSyntaxException {
return Race.fromName(reader.readUnquotedString(), Race.EARTH);
}
@Override
public Collection<String> getExamples() {
return EXAMPLES;
}
}

View file

@ -0,0 +1,53 @@
package com.minelittlepony.unicopia.command;
import java.util.function.BiFunction;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.SpeciesList;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
class RacelistCommand {
static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
LiteralArgumentBuilder<ServerCommandSource> builder = CommandManager.literal("racelist").requires(s -> s.hasPermissionLevel(4));
builder.then(CommandManager.literal("allow")
.then(CommandManager.argument("race", new RaceArgument())
.executes(context -> toggle(context.getSource(), context.getSource().getPlayer(), context.getArgument("race", Race.class), "allowed", SpeciesList::unwhiteListRace))
));
builder.then(CommandManager.literal("disallow")
.then(CommandManager.argument("race", new RaceArgument())
.executes(context -> toggle(context.getSource(), context.getSource().getPlayer(), context.getArgument("race", Race.class), "disallowed", SpeciesList::whiteListRace))
));
dispatcher.register(builder);
}
static int toggle(ServerCommandSource source, ServerPlayerEntity player, Race race, String action, BiFunction<SpeciesList, Race, Boolean> func) {
String translationKey = "commands.racelist." + action;
if (!func.apply(SpeciesList.instance(), race)) {
translationKey += ".failed";
}
Text formattedName = new TranslatableText(race.name().toLowerCase());
formattedName.getStyle().setColor(Formatting.GOLD);
Text comp = new TranslatableText(translationKey, formattedName);
comp.getStyle().setColor(Formatting.GREEN);
player.sendMessage(comp);
source.sendFeedback(new TranslatableText(translationKey + ".other", player.getName(), formattedName), true);
return 0;
}
}

View file

@ -0,0 +1,124 @@
package com.minelittlepony.unicopia.command;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.SpeciesList;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.command.arguments.EntityArgumentType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.world.GameRules;
class SpeciesCommand {
static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
LiteralArgumentBuilder<ServerCommandSource> builder = CommandManager.literal("race");
builder.then(CommandManager.literal("get")
.executes(context -> get(context.getSource(), context.getSource().getPlayer(), true))
.then(CommandManager.argument("target", EntityArgumentType.player())
.executes(context -> get(context.getSource(), EntityArgumentType.getPlayer(context, "target"), false))
));
builder.then(CommandManager.literal("set")
.then(CommandManager.argument("race", new RaceArgument())
.executes(context -> set(context.getSource(), context.getSource().getPlayer(), context.getArgument("race", Race.class), true))
.then(CommandManager.argument("target", EntityArgumentType.player())
.executes(context -> set(context.getSource(), EntityArgumentType.getPlayer(context, "target"), context.getArgument("race", Race.class), false))
)));
builder.then(CommandManager.literal("describe")
.then(CommandManager.argument("race", new RaceArgument())
.executes(context -> describe(context.getSource().getPlayer(), context.getArgument("race", Race.class))
)));
builder.then(CommandManager.literal("list")
.executes(context -> list(context.getSource().getPlayer())
));
dispatcher.register(builder);
}
static int set(ServerCommandSource source, PlayerEntity player, Race race, boolean isSelf) {
if (SpeciesList.instance().speciesPermitted(race, player)) {
SpeciesList.instance().getPlayer(player).setSpecies(race);
Text formattedName = new TranslatableText(race.name().toLowerCase());
if (!isSelf) {
source.sendFeedback(new TranslatableText("commands.race.success.other", player.getName(), formattedName), true);
} else {
if (player.getEntityWorld().getGameRules().getBoolean(GameRules.SEND_COMMAND_FEEDBACK)) {
player.sendMessage(new TranslatableText("commands.race.success.self"));
}
source.sendFeedback(new TranslatableText("commands.race.success.otherself", player.getName(), formattedName), true);
}
} else if (player.getEntityWorld().getGameRules().getBoolean(GameRules.SEND_COMMAND_FEEDBACK)) {
player.sendMessage(new TranslatableText("commands.race.permission"));
}
return 0;
}
static int get(ServerCommandSource source, PlayerEntity player, boolean isSelf) {
Race spec = SpeciesList.instance().getPlayer(player).getSpecies();
String name = "commands.race.tell.";
name += isSelf ? "self" : "other";
Text race = new TranslatableText(spec.getTranslationKey());
Text message = new TranslatableText(name);
race.getStyle().setColor(Formatting.GOLD);
message.append(race);
player.sendMessage(message);
return 0;
}
static int list(PlayerEntity player) {
player.sendMessage(new TranslatableText("commands.race.list"));
Text message = new LiteralText("");
boolean first = true;
for (Race i : Race.values()) {
if (!i.isDefault() && SpeciesList.instance().speciesPermitted(i, player)) {
message.append(new TranslatableText((!first ? "\n" : "") + " - " + i.name().toLowerCase()));
first = false;
}
}
message.getStyle().setColor(Formatting.GOLD);
player.sendMessage(message);
return 0;
}
static int describe(PlayerEntity player, Race species) {
String name = species.name().toLowerCase();
Text line1 = new TranslatableText(String.format("commands.race.describe.%s.1", name));
line1.getStyle().setColor(Formatting.YELLOW);
player.sendMessage(line1);
player.sendMessage(new TranslatableText(String.format("commands.race.describe.%s.2", name)));
Text line3 = new TranslatableText(String.format("commands.race.describe.%s.3", name));
line3.getStyle().setColor(Formatting.RED);
player.sendMessage(line3);
return 0;
}
}

View file

@ -0,0 +1,10 @@
package com.minelittlepony.unicopia.ducks;
import com.minelittlepony.unicopia.entity.capabilities.ItemEntityCapabilities;
public interface IItemEntity extends IRaceContainerHolder<ItemEntityCapabilities> {
int getAge();
int getPickupDelay();
}

View file

@ -6,8 +6,8 @@ import javax.annotation.Nullable;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import com.minelittlepony.unicopia.item.MagicGemItem; import com.minelittlepony.unicopia.item.MagicGemItem;
import com.minelittlepony.unicopia.spell.SpellAffinity; import com.minelittlepony.unicopia.magic.Affinity;
import com.minelittlepony.unicopia.spell.SpellRegistry; import com.minelittlepony.unicopia.magic.spells.SpellRegistry;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -30,7 +30,7 @@ public class SpellCraftingEvent {
static class Condition implements IUnlockCondition<Event> { static class Condition implements IUnlockCondition<Event> {
@Nonnull @Nonnull
SpellAffinity affinity; Affinity affinity;
@Expose @Expose
String spell; String spell;
@ -39,7 +39,7 @@ public class SpellCraftingEvent {
require(json, "affinity"); require(json, "affinity");
require(json, "spell"); require(json, "spell");
affinity = SpellAffinity.of(json.get("affinity").getAsString()); affinity = Affinity.of(json.get("affinity").getAsString());
spell = json.get("spell").getAsString(); spell = json.get("spell").getAsString();
} }

View file

@ -0,0 +1,62 @@
package com.minelittlepony.unicopia.enchanting.recipe;
import java.util.stream.Stream;
import javax.annotation.Nonnull;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.PacketByteBuf;
class AffineIngredient implements SpellIngredient {
static final Serializer<AffineIngredient> SERIALIZER = new Serializer<AffineIngredient>() {
@Override
public AffineIngredient read(JsonElement json) {
return new AffineIngredient(new Identifier(json.getAsJsonObject().get("id").getAsString()));
}
@Override
public AffineIngredient read(PacketByteBuf buff) {
return new AffineIngredient(new Identifier(buff.readString()));
}
@Override
public void write(PacketByteBuf buff, AffineIngredient ingredient) {
buff.writeString(ingredient.res.toString());
}
};
private final Identifier res;
AffineIngredient(Identifier res) {
this.res = res;
}
@Override
public ItemStack getStack() {
return AffineIngredients.instance().getIngredient(res).getStack();
}
@Override
public Stream<ItemStack> getStacks() {
return AffineIngredients.instance().getIngredient(res).getStacks();
}
@Override
public boolean matches(ItemStack other, int materialMult) {
return AffineIngredients.instance().getIngredient(res).matches(other, materialMult);
}
@Nonnull
static SpellIngredient parse(JsonObject json) {
return SERIALIZER.read(json);
}
@Override
public Serializer<?> getSerializer() {
return SERIALIZER;
}
}

View file

@ -1,9 +1,6 @@
package com.minelittlepony.unicopia.enchanting.recipe; package com.minelittlepony.unicopia.enchanting.recipe;
import java.util.Map; import java.util.Map;
import java.util.stream.Stream;
import javax.annotation.Nonnull;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
@ -11,7 +8,6 @@ import com.google.gson.JsonParseException;
import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.util.AssetWalker; import com.minelittlepony.util.AssetWalker;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
public class AffineIngredients { public class AffineIngredients {
@ -50,33 +46,4 @@ public class AffineIngredients {
storedIngredients.put(id, ingredient); storedIngredients.put(id, ingredient);
} }
} }
static class AffineIngredient implements SpellIngredient {
private final Identifier res;
AffineIngredient(Identifier res) {
this.res = res;
}
@Override
public ItemStack getStack() {
return instance().getIngredient(res).getStack();
}
@Override
public Stream<ItemStack> getStacks() {
return instance().getIngredient(res).getStacks();
}
@Override
public boolean matches(ItemStack other, int materialMult) {
return instance().getIngredient(res).matches(other, materialMult);
}
@Nonnull
static SpellIngredient parse(JsonObject json) {
return new AffineIngredient(new Identifier(json.get("id").getAsString()));
}
}
} }

View file

@ -3,14 +3,10 @@ package com.minelittlepony.unicopia.enchanting.recipe;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Stream; import java.util.stream.Stream;
import javax.annotation.Nullable;
import com.google.common.collect.Streams; import com.google.common.collect.Streams;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import com.minelittlepony.unicopia.enchanting.recipe.AffineIngredients.AffineIngredient;
import com.minelittlepony.unicopia.enchanting.recipe.SpellIngredient.Serializer;
import com.minelittlepony.unicopia.magic.spells.SpellRegistry; import com.minelittlepony.unicopia.magic.spells.SpellRegistry;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@ -68,7 +64,7 @@ class SingleSpellIngredient implements SpellIngredient {
public Stream<ItemStack> getStacks() { public Stream<ItemStack> getStacks() {
if (!contained.isEmpty()) { if (!contained.isEmpty()) {
DefaultedList<ItemStack> subItems = DefaultedList.of(); DefaultedList<ItemStack> subItems = DefaultedList.of();
contained.getItem().getSubItems(ItemGroup.SEARCH, subItems); contained.getItem().appendStacks(ItemGroup.SEARCH, subItems);
return subItems.stream(); return subItems.stream();
} }

View file

@ -1,5 +1,7 @@
package com.minelittlepony.unicopia.enchanting.recipe; package com.minelittlepony.unicopia.enchanting.recipe;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream; import java.util.stream.Stream;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
@ -8,10 +10,16 @@ import com.google.gson.JsonParseException;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.DefaultedList; import net.minecraft.util.DefaultedList;
import net.minecraft.util.PacketByteBuf; import net.minecraft.util.PacketByteBuf;
import net.minecraft.util.SystemUtil;
public interface SpellIngredient { public interface SpellIngredient {
SpellIngredient EMPTY = new SingleSpellIngredient(ItemStack.EMPTY, false); SpellIngredient EMPTY = new SingleSpellIngredient(ItemStack.EMPTY, false);
Map<String, Serializer<? extends SpellIngredient>> SERIALIZERS = SystemUtil.consume(new HashMap<>(), map -> {
map.put("compound", CompoundSpellIngredient.SERIALIZER);
map.put("single", SingleSpellIngredient.SERIALIZER);
map.put("affine", AffineIngredient.SERIALIZER);
});
Serializer<SpellIngredient> SERIALIZER = new Serializer<SpellIngredient>() { Serializer<SpellIngredient> SERIALIZER = new Serializer<SpellIngredient>() {
@Override @Override
@ -25,12 +33,9 @@ public interface SpellIngredient {
@Override @Override
public SpellIngredient read(PacketByteBuf buff) { public SpellIngredient read(PacketByteBuf buff) {
byte type = buff.readByte(); String type = buff.readString();
if (type == 0) { return SERIALIZERS.get(type).read(buff);
return SingleSpellIngredient.SERIALIZER.read(buff);
}
return CompoundSpellIngredient.SERIALIZER.read(buff);
} }
@Override @Override

View file

@ -155,24 +155,24 @@ public class CloudEntity extends FlyingEntity implements ICloudEntity, IInAnimat
} }
@Override @Override
protected void collideWithEntity(Entity other) { protected void pushAway(Entity other) {
if (other instanceof CloudEntity || other instanceof PlayerEntity) { if (other instanceof CloudEntity || other instanceof PlayerEntity) {
if (other.y > y) { if (other.y > y) {
return; return;
} }
super.collideWithEntity(other); super.pushAway(other);
} }
} }
@Override @Override
public void applyEntityCollision(Entity other) { public void pushAwayFrom(Entity other) {
if (other instanceof PlayerEntity) { if (other instanceof PlayerEntity) {
if (EquinePredicates.INTERACT_WITH_CLOUDS.test((PlayerEntity)other)) { if (EquinePredicates.INTERACT_WITH_CLOUDS.test((PlayerEntity)other)) {
super.applyEntityCollision(other); super.pushAwayFrom(other);
} }
} else if (other instanceof CloudEntity) { } else if (other instanceof CloudEntity) {
super.applyEntityCollision(other); super.pushAwayFrom(other);
} }
} }

View file

@ -7,13 +7,11 @@ import javax.annotation.Nullable;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.minelittlepony.unicopia.EquinePredicates; import com.minelittlepony.unicopia.EquinePredicates;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.UParticles; import com.minelittlepony.unicopia.UParticles;
import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.ability.IPower;
import com.minelittlepony.unicopia.particles.ParticleEmitter;
import com.minelittlepony.util.MagicalDamageSource; import com.minelittlepony.util.MagicalDamageSource;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityDimensions; import net.minecraft.entity.EntityDimensions;
@ -29,7 +27,6 @@ import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.particle.BlockStateParticleEffect; import net.minecraft.particle.BlockStateParticleEffect;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.sound.SoundEvent; import net.minecraft.sound.SoundEvent;
@ -43,18 +40,16 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.world.GameRules; import net.minecraft.world.GameRules;
import net.minecraft.world.World; import net.minecraft.world.World;
public class EntityCuccoon extends LivingEntity implements IMagicals, IInAnimate { public class CuccoonEntity extends LivingEntity implements IMagicals, IInAnimate {
private static final TrackedData<Integer> STRUGGLE_COUNT = DataTracker.registerData(EntityCuccoon.class, TrackedDataHandlerRegistry.INTEGER); private static final TrackedData<Integer> STRUGGLE_COUNT = DataTracker.registerData(CuccoonEntity.class, TrackedDataHandlerRegistry.INTEGER);
private final List<ItemStack> armour = Lists.newArrayList(); private final List<ItemStack> armour = Lists.newArrayList();
private boolean captiveLastSneakState; private boolean captiveLastSneakState;
public EntityCuccoon(EntityType<EntityCuccoon> type, World world) { public CuccoonEntity(EntityType<CuccoonEntity> type, World world) {
super(type, world); super(type, world);
//width = 1.5F;
//height = 1.6F;
} }
@Override @Override
@ -140,9 +135,11 @@ public class EntityCuccoon extends LivingEntity implements IMagicals, IInAnimate
} }
if (world.isClient) { if (world.isClient) {
double x = this.x + width * random.nextFloat() - width/2; EntityDimensions dims = getDimensions(getPose());
double y = this.y + height * random.nextFloat();
double z = this.z + width * random.nextFloat() - width/2; double x = this.x + dims.width * random.nextFloat() - dims.width/2;
double y = this.y + dims.height * random.nextFloat();
double z = this.z + dims.width * random.nextFloat() - dims.width/2;
world.addParticle(ParticleTypes.DRIPPING_LAVA, x, y, z, 0, 0, 0); world.addParticle(ParticleTypes.DRIPPING_LAVA, x, y, z, 0, 0, 0);
} }
@ -159,7 +156,7 @@ public class EntityCuccoon extends LivingEntity implements IMagicals, IInAnimate
if (player.canConsume(false) || player.getHealth() < player.getHealthMaximum()) { if (player.canConsume(false) || player.getHealth() < player.getHealthMaximum()) {
DamageSource d = MagicalDamageSource.causePlayerDamage("feed", player); DamageSource d = MagicalDamageSource.causePlayerDamage("feed", player);
IPower.spawnParticles(UParticles.CHANGELING_MAGIC, this, 7); SpeciesList.instance().getPlayer(player).spawnParticles(UParticles.CHANGELING_MAGIC, 7);
if (passenger instanceof LivingEntity) { if (passenger instanceof LivingEntity) {
if (player.hasStatusEffect(StatusEffects.NAUSEA)) { if (player.hasStatusEffect(StatusEffects.NAUSEA)) {
@ -237,7 +234,7 @@ public class EntityCuccoon extends LivingEntity implements IMagicals, IInAnimate
} }
@Override @Override
protected void onDeathUpdate() { protected void updatePostDeath() {
if (++deathTime == 20) { if (++deathTime == 20) {
if (!world.isClient && lastAttackedTicks > 0 && canDropLootAndXp() && world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) { if (!world.isClient && lastAttackedTicks > 0 && canDropLootAndXp() && world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) {
int i = getCurrentExperience(attackingPlayer); int i = getCurrentExperience(attackingPlayer);
@ -270,12 +267,12 @@ public class EntityCuccoon extends LivingEntity implements IMagicals, IInAnimate
} }
@Override @Override
protected void collideWithEntity(Entity entity) { protected void pushAway(Entity entity) {
if (canBeRidden(entity)) { if (canAddPassenger(entity)) {
entity.playSound(USounds.SLIME_ADVANCE, 1, 1); entity.playSound(USounds.SLIME_ADVANCE, 1, 1);
entity.startRiding(this, true); entity.startRiding(this, true);
} else { } else {
super.collideWithEntity(entity); super.pushAway(entity);
} }
} }

View file

@ -1,84 +0,0 @@
package com.minelittlepony.unicopia.entity;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.UClient;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World;
public class EntityFakeClientPlayer extends AbstractClientPlayer implements IOwned<PlayerEntity> {
private NetworkPlayerInfo playerInfo;
private PlayerEntity owner;
public EntityFakeClientPlayer(World world, GameProfile profile) {
super(world, profile);
}
@Override
@Nullable
protected NetworkPlayerInfo getPlayerInfo() {
if (playerInfo == null) {
NetHandlerPlayClient connection = MinecraftClient.instance().getConnection();
playerInfo = connection.getPlayerInfo(getGameProfile().getId());
if (playerInfo == null) {
playerInfo = new NetworkPlayerInfo(getGameProfile());
}
}
return playerInfo;
}
@Override
public boolean isPlayer() {
return false;
}
@Override
protected void playEquipSound(ItemStack stack) {
/*noop*/
}
@Override
public boolean isUser() {
return false;
}
@Override
public boolean getAlwaysRenderNameTag() {
return !UClient.instance().isClientPlayer(getOwner());
}
@Override
public boolean getAlwaysRenderNameTagForRender() {
return getAlwaysRenderNameTag();
}
@Override
public PlayerEntity getOwner() {
return owner;
}
@Override
public void setOwner(PlayerEntity owner) {
this.owner = owner;
}
@Override
public ITextComponent getDisplayName() {
ITextComponent name = super.getDisplayName();
name.getStyle().setItalic(true);
return name;
}
}

View file

@ -1,56 +0,0 @@
package com.minelittlepony.unicopia.entity;
import com.minelittlepony.unicopia.UClient;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.FakePlayer;
public class EntityFakeServerPlayer extends FakePlayer implements IOwned<PlayerEntity> {
private PlayerEntity owner;
public EntityFakeServerPlayer(WorldServer world, GameProfile profile) {
super(world, profile);
}
@Override
public boolean isPlayer() {
return false;
}
@Override
protected void playEquipSound(ItemStack stack) {
/*noop*/
}
@Override
public PlayerEntity getOwner() {
return owner;
}
@Override
public void setOwner(PlayerEntity owner) {
this.owner = owner;
}
@Override
public boolean getAlwaysRenderNameTag() {
return !UClient.instance().isClientPlayer(getOwner());
}
@Override
public boolean getAlwaysRenderNameTagForRender() {
return getAlwaysRenderNameTag();
}
@Override
public ITextComponent getDisplayName() {
ITextComponent name = super.getDisplayName();
name.getStyle().setItalic(true);
return name;
}
}

View file

@ -1,75 +0,0 @@
package com.minelittlepony.unicopia.entity;
import java.util.List;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.EquinePredicates;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
public class EntityRacingCloud extends CloudEntity {
public EntityRacingCloud(EntityType<EntityRacingCloud> type, World world) {
super(type, world);
setCloudSize(1);
}
@Override
public boolean canBeSteered() {
return true;
}
@Override
protected boolean canFitPassenger(Entity passenger) {
return getPassengers().size() < getCloudSize();
}
@Override
@Nullable
public Entity getControllingPassenger() {
List<Entity> list = getPassengers();
return list.isEmpty() ? null : list.get(0);
}
@Override
public EnumActionResult applyPlayerInteraction(PlayerEntity player, Vec3d vec, EnumHand hand) {
if (!(isBeingRidden() || isRidingOrBeingRiddenBy(player)) && hand == EnumHand.MAIN_HAND) {
if (EquinePredicates.INTERACT_WITH_CLOUDS.test(player)) {
if (!getStationary()) {
player.startRiding(this);
return EnumActionResult.SUCCESS;
}
}
}
return EnumActionResult.FAIL;
}
@Override
public void onUpdate() {
Entity riddenByEntity = getControllingPassenger();
if (riddenByEntity != null && canPassengerSteer()) {
LivingEntity rider = (LivingEntity)riddenByEntity;
double speed = 1.5F * rider.moveForward / 5;
double horizontalDriving = (riddenByEntity.rotationYaw - rider.moveStrafing * 90) * Math.PI / 180;
motionX += -Math.sin(horizontalDriving) * speed;
motionZ += Math.cos(horizontalDriving) * speed;
double pitch = riddenByEntity.rotationPitch * Math.PI / 180;
motionY += -Math.sin(pitch) * (speed / 20);
} else {
motionY = 0;
}
super.onUpdate();
}
}

View file

@ -29,13 +29,13 @@ public interface IEntity extends InbtSerialisable, IUpdatable {
} }
/** /**
* Called at the beginning of a player's update cycle. * Called at the beginning of an update cycle.
*/ */
void beforeUpdate(); boolean beforeUpdate();
/** /**
* Event triggered when this player is hit by a projectile. * Event triggered when this entity is hit by a projectile.
*/ */
default boolean onProjectileImpact(ProjectileEntity projectile) { default boolean onProjectileImpact(ProjectileEntity projectile) {
return false; return false;

View file

@ -39,26 +39,26 @@ import net.minecraft.world.World;
* *
* Can also carry a spell if needed. * Can also carry a spell if needed.
*/ */
public class AdvancedProjectileEntity extends ThrownItemEntity implements IMagicals, IAdvancedProjectile, ICaster<LivingEntity> { public class ProjectileEntity extends ThrownItemEntity implements IMagicals, IAdvancedProjectile, ICaster<LivingEntity> {
private static final TrackedData<Float> DAMAGE = DataTracker.registerData(AdvancedProjectileEntity.class, TrackedDataHandlerRegistry.FLOAT); private static final TrackedData<Float> DAMAGE = DataTracker.registerData(ProjectileEntity.class, TrackedDataHandlerRegistry.FLOAT);
private static final TrackedData<Boolean> HYDROPHOBIC = DataTracker.registerData(AdvancedProjectileEntity.class, TrackedDataHandlerRegistry.BOOLEAN); private static final TrackedData<Boolean> HYDROPHOBIC = DataTracker.registerData(ProjectileEntity.class, TrackedDataHandlerRegistry.BOOLEAN);
private static final TrackedData<CompoundTag> EFFECT = DataTracker.registerData(AdvancedProjectileEntity.class, TrackedDataHandlerRegistry.TAG_COMPOUND); private static final TrackedData<CompoundTag> EFFECT = DataTracker.registerData(ProjectileEntity.class, TrackedDataHandlerRegistry.TAG_COMPOUND);
private final EffectSync effectDelegate = new EffectSync(this, EFFECT); private final EffectSync effectDelegate = new EffectSync(this, EFFECT);
private UUID ownerUuid; private UUID ownerUuid;
public AdvancedProjectileEntity(EntityType<AdvancedProjectileEntity> type, World world) { public ProjectileEntity(EntityType<ProjectileEntity> type, World world) {
super(type, world); super(type, world);
} }
public AdvancedProjectileEntity(EntityType<AdvancedProjectileEntity> type, World world, LivingEntity thrower) { public ProjectileEntity(EntityType<ProjectileEntity> type, World world, LivingEntity thrower) {
this(type, world, thrower.x, thrower.y + thrower.getStandingEyeHeight(), thrower.z); this(type, world, thrower.x, thrower.y + thrower.getStandingEyeHeight(), thrower.z);
setOwner(thrower); setOwner(thrower);
} }
public AdvancedProjectileEntity(EntityType<AdvancedProjectileEntity> type, World world, double x, double y, double z) { public ProjectileEntity(EntityType<ProjectileEntity> type, World world, double x, double y, double z) {
super(type, world); super(type, world);
setPosition(x, y, z); setPosition(x, y, z);

View file

@ -0,0 +1,83 @@
package com.minelittlepony.unicopia.entity;
import java.util.List;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.EquinePredicates;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
public class RacingCloudEntity extends CloudEntity {
public RacingCloudEntity(EntityType<RacingCloudEntity> type, World world) {
super(type, world);
setCloudSize(1);
}
@Override
public boolean canBeControlledByRider() {
return true;
}
@Override
protected boolean canAddPassenger(Entity passenger) {
return getPassengerList().size() < getCloudSize();
}
@Override
@Nullable
public Entity getPrimaryPassenger() {
List<Entity> list = getPassengerList();
return list.isEmpty() ? null : list.get(0);
}
@Override
public ActionResult interactAt(PlayerEntity player, Vec3d vec, Hand hand) {
if (!(hasPassengers() || isConnectedThroughVehicle(player)) && hand == Hand.MAIN_HAND) {
if (EquinePredicates.INTERACT_WITH_CLOUDS.test(player)) {
if (!getStationary()) {
player.startRiding(this);
return ActionResult.SUCCESS;
}
}
}
return ActionResult.FAIL;
}
@Override
public void tick() {
Entity jockey = getPrimaryPassenger();
Vec3d vel = getVelocity();
double motionX = vel.x;
double motionY = vel.y;
double motionZ = vel.z;
if (jockey != null && canBeControlledByRider()) {
LivingEntity rider = (LivingEntity)jockey;
double speed = 1.5F * rider.forwardSpeed / 5;
double horizontalDriving = (jockey.yaw - rider.sidewaysSpeed * 90) * Math.PI / 180;
motionX += -Math.sin(horizontalDriving) * speed;
motionZ += Math.cos(horizontalDriving) * speed;
double pitch = jockey.pitch * Math.PI / 180;
motionY += -Math.sin(pitch) * (speed / 20);
} else {
motionY = 0;
}
setVelocity(motionX, motionY, motionZ);
super.tick();
}
}

View file

@ -1,12 +1,16 @@
package com.minelittlepony.unicopia.entity; package com.minelittlepony.unicopia.entity;
import com.minelittlepony.unicopia.magic.ITossedEffect;
import com.minelittlepony.unicopia.projectile.IAdvancedProjectile; import com.minelittlepony.unicopia.projectile.IAdvancedProjectile;
import com.minelittlepony.util.MagicalDamageSource; import com.minelittlepony.util.MagicalDamageSource;
import net.minecraft.client.network.packet.GameStateChangeS2CPacket;
import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.MovementType;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry; import net.minecraft.entity.data.TrackedDataHandlerRegistry;
@ -14,26 +18,28 @@ import net.minecraft.entity.mob.EndermanEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.ArrowEntity; import net.minecraft.entity.projectile.ArrowEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundEvents; import net.minecraft.sound.SoundEvents;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
public class EntitySpear extends ArrowEntity implements IAdvancedProjectile { public class SpearEntity extends ArrowEntity implements IAdvancedProjectile {
private static final TrackedData<ItemStack> ITEM = DataTracker.registerData(EntitySpear.class, TrackedDataHandlerRegistry.ITEM_STACK); private static final TrackedData<ItemStack> ITEM = DataTracker.registerData(SpearEntity.class, TrackedDataHandlerRegistry.ITEM_STACK);
private static final TrackedData<Integer> KNOCKBACK = DataTracker.registerData(EntitySpear.class, TrackedDataHandlerRegistry.INTEGER); private static final TrackedData<Integer> KNOCKBACK = DataTracker.registerData(SpearEntity.class, TrackedDataHandlerRegistry.INTEGER);
public EntitySpear(EntityType<EntitySpear> type, World world) { public SpearEntity(EntityType<SpearEntity> type, World world) {
super(type, world); super(type, world);
} }
public EntitySpear(World world, double x, double y, double z) { public SpearEntity(World world, double x, double y, double z) {
super(world, x, y, z); super(world, x, y, z);
} }
public EntitySpear(World world, LivingEntity shooter) { public SpearEntity(World world, LivingEntity shooter) {
super(world, shooter); super(world, shooter);
} }
@ -45,54 +51,55 @@ public class EntitySpear extends ArrowEntity implements IAdvancedProjectile {
} }
@Override @Override
public void shoot(double x, double y, double z, float velocity, float inaccuracy) { public void setVelocity(double x, double y, double z, float velocity, float inaccuracy) {
setDamage(0); setDamage(0);
super.shoot(x, y, z, velocity, inaccuracy); super.setVelocity(x, y, z, velocity, inaccuracy);
} }
public void move(MoverType type, double x, double y, double z) { @Override
super.move(type, x, y, z); public void move(MovementType type, Vec3d delta) {
super.move(type, delta);
if (type == MoverType.SELF && !inGround) { if (type == MovementType.SELF && !inGround) {
setDamage(getDamage() + 0.02); setDamage(getDamage() + 0.02);
} }
} }
public void setKnockbackStrength(int amount) { @Override
super.setKnockbackStrength(amount); public void method_7449(int amount) {
getDataManager().set(KNOCKBACK, amount); super.method_7449(amount);
getDataTracker().set(KNOCKBACK, amount);
} }
@Override @Override
protected void onHit(RayTraceResult raytraceResultIn) { protected void onEntityHit(EntityHitResult hit) {
Entity entity = raytraceResultIn.entityHit;
Entity entity = hit.getEntity();
if (entity != null) { if (entity != null) {
Vec3d vel = getVelocity(); Vec3d vel = getVelocity();
double speed = vel.length(); double speed = vel.length();
int damage = MathHelper.ceil(speed * getDamage()); int damage = MathHelper.ceil(Math.max(speed * this.getDamage(), 0));
if (getIsCritical()) { if (isCritical()) {
damage += random.nextInt(damage / 2 + 2); damage += random.nextInt(damage / 2 + 2);
} }
DamageSource damagesource = MagicalDamageSource.causeIndirect("spear", this, shootingEntity == null ? this : shootingEntity); Entity archer = getOwner();
DamageSource damagesource = MagicalDamageSource.causeIndirect("spear", this, archer == null ? this : archer);
if (isBurning() && !(entity instanceof EntityEnderman)) { if (isOnFire() && !(entity instanceof EndermanEntity)) {
entity.setFire(5); entity.setOnFireFor(5);
} }
if (entity.attackEntityFrom(damagesource, damage)) { if (entity.damage(damagesource, damage)) {
if (entity instanceof LivingEntity) { if (entity instanceof LivingEntity) {
LivingEntity entitylivingbase = (LivingEntity)entity; LivingEntity target = (LivingEntity)entity;
if (!world.isClient) { if (!world.isClient) {
entitylivingbase.setStuckArrows(entitylivingbase.getStuckArrows() + 1); target.setStuckArrows(target.getStuckArrows() + 1);
} }
int knockback = getDataTracker().get(KNOCKBACK); int knockback = getDataTracker().get(KNOCKBACK);
@ -102,22 +109,22 @@ public class EntitySpear extends ArrowEntity implements IAdvancedProjectile {
double f1 = MathHelper.sqrt(vel.x * vel.x + vel.z * vel.z); double f1 = MathHelper.sqrt(vel.x * vel.x + vel.z * vel.z);
if (f1 > 0) { if (f1 > 0) {
entitylivingbase.addVelocity( target.addVelocity(
vel.x * knockback * 0.6000000238418579D / f1, vel.x * knockback * 0.6000000238418579D / f1,
0.1D, 0.1D,
vel.z * knockback * 0.6000000238418579D / f1); vel.z * knockback * 0.6000000238418579D / f1);
} }
} }
if (shootingEntity instanceof LivingEntity) { if (!this.world.isClient && archer instanceof LivingEntity) {
EnchantmentHelper.applyThornEnchantments(entitylivingbase, shootingEntity); EnchantmentHelper.onUserDamaged(target, archer);
EnchantmentHelper.applyArthropodEnchantments((LivingEntity)shootingEntity, entitylivingbase); EnchantmentHelper.onTargetDamaged((LivingEntity)archer, target);
} }
arrowHit(entitylivingbase); onHit(target);
if (shootingEntity != null && entitylivingbase != shootingEntity && entitylivingbase instanceof PlayerEntity && shootingEntity instanceof ServerPlayerEntity) { if (archer != null && target != archer && target instanceof PlayerEntity && archer instanceof ServerPlayerEntity) {
((ServerPlayerEntity)shootingEntity).connection.sendPacket(new SPacketChangeGameState(6, 0)); ((ServerPlayerEntity)archer).networkHandler.sendPacket(new GameStateChangeS2CPacket(6, 0));
} }
} }
@ -130,8 +137,6 @@ public class EntitySpear extends ArrowEntity implements IAdvancedProjectile {
return; return;
} }
} }
super.onHit(raytraceResultIn);
} }
@Override @Override
@ -141,7 +146,7 @@ public class EntitySpear extends ArrowEntity implements IAdvancedProjectile {
@Override @Override
public void setItem(ItemStack stack) { public void setItem(ItemStack stack) {
getDataTracker().set(ITEM, new ItemStack(stack.getItem(), 1, stack.getMetadata())); getDataTracker().set(ITEM, stack.copy());
} }
@Override @Override
@ -166,6 +171,19 @@ public class EntitySpear extends ArrowEntity implements IAdvancedProjectile {
@Override @Override
public void launch(Entity shooter, float pitch, float yaw, float pitchOffset, float velocity, float inaccuracy) { public void launch(Entity shooter, float pitch, float yaw, float pitchOffset, float velocity, float inaccuracy) {
shoot(shooter, pitch, yaw, pitchOffset, velocity, inaccuracy); method_7474(shooter, pitch, yaw, pitchOffset, velocity, inaccuracy);
}
@Override
public void setGravity(boolean gravity) {
}
@Override
public void setOwner(LivingEntity owner) {
setOwner((Entity)owner);
}
@Override
public void setEffect(ITossedEffect effect) {
} }
} }

View file

@ -11,7 +11,6 @@ import net.minecraft.entity.EntityData;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnType; import net.minecraft.entity.SpawnType;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.TypeFilterableList; import net.minecraft.util.TypeFilterableList;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -20,7 +19,6 @@ import net.minecraft.world.IWorld;
import net.minecraft.world.LocalDifficulty; import net.minecraft.world.LocalDifficulty;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.biome.Biome.SpawnEntry; import net.minecraft.world.biome.Biome.SpawnEntry;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.WorldChunk; import net.minecraft.world.chunk.WorldChunk;
public class WildCloudEntity extends CloudEntity { public class WildCloudEntity extends CloudEntity {
@ -31,10 +29,10 @@ public class WildCloudEntity extends CloudEntity {
public WildCloudEntity(EntityType<WildCloudEntity> type, World world) { public WildCloudEntity(EntityType<WildCloudEntity> type, World world) {
super(type, world); super(type, world);
preventEntitySpawning = true; inanimate = true;
} }
@Override /*@Override
public boolean isNotColliding() { public boolean isNotColliding() {
Box boundingbox = getBoundingBox(); Box boundingbox = getBoundingBox();
@ -42,22 +40,24 @@ public class WildCloudEntity extends CloudEntity {
&& world.isSkyVisible(getBlockPos()) && world.isSkyVisible(getBlockPos())
&& world.doesNotCollide(this, boundingbox) && world.doesNotCollide(this, boundingbox)
&& !world.intersectsFluid(boundingbox); && !world.intersectsFluid(boundingbox);
} }*/
/** /**
* Returns true if there are no solid, live entities in the specified Box, excluding the given entity * Returns true if there are no solid, live entities in the specified Box, excluding the given entity
* *
* @ref World.checkNoEntityCollision(Box area, Entity entity) * @ref World.checkNoEntityCollision(Box area, Entity entity)
*/ */
public boolean checkNoEntityCollision(Box area, Entity entity) { /*public boolean checkNoEntityCollision(Box area, Entity entity) {
ServerWorld s;
((ServerWorld)world).intersectsEntities(entity_1, voxelShape_1)
for (Entity i : world.getEntities(entity, area)) { for (Entity i : world.getEntities(entity, area)) {
if (!i.removed && (i.preventEntitySpawning || i instanceof CloudEntity) && (!entity.hasVehicle() || !entity.isConnectedThroughVehicle(i))) { if (!i.removed && (i.inanimate || i instanceof CloudEntity) && (!entity.hasVehicle() || !entity.isConnectedThroughVehicle(i))) {
return false; return false;
} }
} }
return true; return true;
} }*/
@Override @Override
public boolean canSpawn(IWorld world, SpawnType type) { public boolean canSpawn(IWorld world, SpawnType type) {
@ -93,17 +93,17 @@ public class WildCloudEntity extends CloudEntity {
targetAltitude = getRandomFlyingHeight(); targetAltitude = getRandomFlyingHeight();
if (y < minSpawnHeight) { if (y < minSpawnHeight) {
minSpawnHeight += world.random.nextInt(Math.max(1, (int)getMaximumFlyingHeight() - (int)minSpawnHeight)); minSpawnHeight += random.nextInt(Math.max(1, (int)getMaximumFlyingHeight() - (int)minSpawnHeight));
setPositionAndAngles(x, minSpawnHeight - 1, z, yaw, pitch); setPositionAndAngles(x, minSpawnHeight - 1, z, yaw, pitch);
collideWithNearbyEntities(); moveToBoundingBoxCenter();
} }
if (world.hasRain(getBlockPos())) { if (this.world.hasRain(getBlockPos())) {
setIsRaining(true); setIsRaining(true);
} }
if (world.isThundering()) { if (this.world.isThundering()) {
setIsThundering(true); setIsThundering(true);
} }

View file

@ -4,7 +4,7 @@ import java.util.UUID;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.minelittlepony.unicopia.UClient; import com.minelittlepony.unicopia.InteractionManager;
import com.minelittlepony.unicopia.ability.IAbilityReceiver; import com.minelittlepony.unicopia.ability.IAbilityReceiver;
import com.minelittlepony.unicopia.enchanting.IPageOwner; import com.minelittlepony.unicopia.enchanting.IPageOwner;
import com.minelittlepony.unicopia.entity.IFlight; import com.minelittlepony.unicopia.entity.IFlight;
@ -132,24 +132,7 @@ public interface IPlayer extends ICaster<PlayerEntity>, IRaceContainer<PlayerEnt
* Returns true if this player is the use. * Returns true if this player is the use.
*/ */
default boolean isClientPlayer() { default boolean isClientPlayer() {
return UClient.instance().isClientPlayer(getOwner()); return InteractionManager.instance().isClientPlayer(getOwner());
}
static PlayerEntity fromServer(UUID playerId) {
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
if (server == null) {
return UClient.instance().getPlayerByUUID(playerId);
}
Entity e = server.getPlayerManager().getPlayer(playerId);
if (e instanceof PlayerEntity) {
return (PlayerEntity)e;
}
return null;
} }
static boolean equal(GameProfile one, GameProfile two) { static boolean equal(GameProfile one, GameProfile two) {

View file

@ -1,11 +1,14 @@
package com.minelittlepony.unicopia.entity.capabilities; package com.minelittlepony.unicopia.entity.capabilities;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.ducks.IItemEntity;
import com.minelittlepony.unicopia.entity.IOwned; import com.minelittlepony.unicopia.entity.IOwned;
import com.minelittlepony.unicopia.entity.IRaceContainer; import com.minelittlepony.unicopia.entity.IRaceContainer;
import net.minecraft.entity.ItemEntity; import net.minecraft.entity.ItemEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.ActionResult;
public class ItemEntityCapabilities implements IRaceContainer<ItemEntity>, IOwned<ItemEntity> { public class ItemEntityCapabilities implements IRaceContainer<ItemEntity>, IOwned<ItemEntity> {
@ -23,8 +26,14 @@ public class ItemEntityCapabilities implements IRaceContainer<ItemEntity>, IOwne
} }
@Override @Override
public void beforeUpdate() { public boolean beforeUpdate() {
ItemStack stack = owner.getStack();
if (!stack.isEmpty() && stack.getItem() instanceof TickableItem) {
return ((TickableItem)stack.getItem()).onGroundTick((IItemEntity)owner) == ActionResult.SUCCESS;
}
return false;
} }
@Override @Override
@ -62,4 +71,8 @@ public class ItemEntityCapabilities implements IRaceContainer<ItemEntity>, IOwne
public ItemEntity getOwner() { public ItemEntity getOwner() {
return owner; return owner;
} }
public interface TickableItem {
ActionResult onGroundTick(IItemEntity entity);
}
} }

View file

@ -13,7 +13,7 @@ import com.minelittlepony.unicopia.UItems;
import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.ability.IAbilityReceiver; import com.minelittlepony.unicopia.ability.IAbilityReceiver;
import com.minelittlepony.unicopia.enchanting.PageState; import com.minelittlepony.unicopia.enchanting.PageState;
import com.minelittlepony.unicopia.entity.EntityCuccoon; import com.minelittlepony.unicopia.entity.CuccoonEntity;
import com.minelittlepony.unicopia.entity.IFlight; import com.minelittlepony.unicopia.entity.IFlight;
import com.minelittlepony.unicopia.entity.IFood; import com.minelittlepony.unicopia.entity.IFood;
import com.minelittlepony.unicopia.entity.IGravity; import com.minelittlepony.unicopia.entity.IGravity;

View file

@ -6,16 +6,16 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory; import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.PacketByteBuf;
public class ContainerOfHolding extends Container { public class ContainerOfHolding extends Container {
private final InventoryOfHolding inventory; private final InventoryOfHolding inventory;
private ItemStack sourceStack; private ItemStack sourceStack;
public ContainerOfHolding(PlayerEntity player) { public ContainerOfHolding(int num, Identifier id, PlayerEntity player, PacketByteBuf buff) {
// TODO super(null, num);
super(null, 0);
sourceStack = player.getStackInHand(Hand.MAIN_HAND); sourceStack = player.getStackInHand(Hand.MAIN_HAND);
inventory = InventoryOfHolding.getInventoryFromStack(sourceStack); inventory = InventoryOfHolding.getInventoryFromStack(sourceStack);

View file

@ -4,7 +4,6 @@ import javax.annotation.Nonnull;
import com.minelittlepony.unicopia.EquinePredicates; import com.minelittlepony.unicopia.EquinePredicates;
import com.minelittlepony.unicopia.SpeciesList; import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.enchanting.IPageUnlockListener; import com.minelittlepony.unicopia.enchanting.IPageUnlockListener;
import com.minelittlepony.unicopia.magic.spells.SpellRegistry; import com.minelittlepony.unicopia.magic.spells.SpellRegistry;
import com.minelittlepony.unicopia.world.UWorld; import com.minelittlepony.unicopia.world.UWorld;
@ -17,6 +16,8 @@ import net.minecraft.inventory.BasicInventory;
import net.minecraft.inventory.Inventory; import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeType;
import net.minecraft.sound.SoundEvents; import net.minecraft.sound.SoundEvents;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -72,7 +73,10 @@ public class SpellBookContainer extends Container {
ItemStack current = craftResult.getInvStack(0); ItemStack current = craftResult.getInvStack(0);
if (!current.isEmpty()) { if (!current.isEmpty()) {
ItemStack crafted = Unicopia.getCraftingManager().findMatchingResult(craftMatrix, worldObj); // TODO: RecipeType.SPELL_BOOK
ItemStack crafted = player.world.getRecipeManager().getFirstMatch(RecipeType.CRAFTING, craftMatrix, worldObj)
.map(Recipe::getOutput)
.orElse(ItemStack.EMPTY);
if (!crafted.isEmpty()) { if (!crafted.isEmpty()) {
resultSlot.setCrafted(true); resultSlot.setCrafted(true);

View file

@ -45,7 +45,7 @@ public class SpellbookResultSlot extends SpellBookContainer.SpellbookSlot {
ItemStack current = craftMatrix.getCraftResultMatrix().getInvStack(0); ItemStack current = craftMatrix.getCraftResultMatrix().getInvStack(0);
craftMatrix.getCraftResultMatrix().setInvStack(0, stack); craftMatrix.getCraftResultMatrix().setInvStack(0, stack);
// TODO: URecipeType.GEM_ENCHANTMENT // TODO: URecipeType.SPELL_BOOK
DefaultedList<ItemStack> remaining = player.world.getRecipeManager().getRemainingStacks(RecipeType.CRAFTING, craftMatrix, player.world); DefaultedList<ItemStack> remaining = player.world.getRecipeManager().getRemainingStacks(RecipeType.CRAFTING, craftMatrix, player.world);
craftMatrix.getCraftResultMatrix().setInvStack(0, current); craftMatrix.getCraftResultMatrix().setInvStack(0, current);

View file

@ -0,0 +1,297 @@
package com.minelittlepony.unicopia.item;
import java.util.List;
import java.util.UUID;
import javax.annotation.Nullable;
import com.google.common.collect.Multimap;
import com.minelittlepony.unicopia.InteractionManager;
import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.UItems;
import com.minelittlepony.unicopia.ducks.IItemEntity;
import com.minelittlepony.unicopia.entity.capabilities.IPlayer;
import com.minelittlepony.unicopia.magic.Affinity;
import com.minelittlepony.unicopia.magic.items.IDependable;
import com.minelittlepony.unicopia.world.UWorld;
import com.minelittlepony.util.MagicalDamageSource;
import com.minelittlepony.util.VecHelper;
import com.minelittlepony.unicopia.entity.capabilities.ItemEntityCapabilities;
import net.minecraft.util.ChatUtil;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.MovementType;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.ArmorMaterial;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.recipe.Ingredient;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.LocalDifficulty;
import net.minecraft.world.World;
import net.minecraft.world.explosion.Explosion.DestructionType;
public class AlicornAmuletItem extends ArmorItem implements IDependable, ItemEntityCapabilities.TickableItem {
private static final UUID[] MODIFIERS = new UUID[] {
UUID.fromString("845DB27C-C624-495F-8C9F-6020A9A58B6B"),
UUID.fromString("D8499B04-0E66-4726-AB29-64469D734E0D"),
UUID.fromString("9F3D476D-C118-4544-8365-64846904B48E"),
UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150")
};
public AlicornAmuletItem() {
super(new Material(), EquipmentSlot.CHEST, new Settings().maxCount(1));
}
@Override
public Affinity getAffinity() {
return Affinity.BAD;
}
@Override
public ActionResult onGroundTick(IItemEntity item) {
ItemEntity entity = item.getRaceContainer().getOwner();
World world = entity.world;
double x = entity.x + world.random.nextFloat() - 0.5;
double z = entity.z + world.random.nextFloat() - 0.5;
double y = entity.y + world.random.nextFloat();
ParticleEffect particle = world.random.nextBoolean() ? ParticleTypes.LARGE_SMOKE : ParticleTypes.FLAME;
world.addParticle(particle, x, y, z, 0, 0, 0);
if (world.random.nextInt(500) == 0) {
world.playSound(null, entity.getBlockPos(), SoundEvents.AMBIENT_CAVE, SoundCategory.HOSTILE, 0.5F, 1);
}
Vec3d position = entity.getPos();
VecHelper.findAllEntitiesInRange(entity, world, entity.getBlockPos(), 10)
.filter(e -> e instanceof PlayerEntity)
.sorted((a, b) -> (int)(a.getPos().distanceTo(position) - b.getPos().distanceTo(position)))
.findFirst()
.ifPresent(player -> interactWithPlayer(entity, (PlayerEntity)player));
return ActionResult.PASS;
}
protected void interactWithPlayer(ItemEntity entity, PlayerEntity player) {
entity.move(MovementType.SELF, player.getPos().subtract(entity.getPos()).multiply(0.02));
if (!player.world.isClient && !entity.removed) {
if (player.getPos().distanceTo(entity.getPos()) < 3) {
if (entity.world.random.nextInt(150) == 0) {
TypedActionResult<ItemStack> result = use(player.world, player, Hand.MAIN_HAND);
if (result.getResult() == ActionResult.SUCCESS) {
entity.setPickupDelay(1000);
entity.remove();
}
}
}
}
}
@Environment(EnvType.CLIENT)
@Override
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
IPlayer iplayer = InteractionManager.instance().getIPlayer();
if (iplayer != null) {
int attachedTime = iplayer.getInventory().getTicksAttached(this);
if (attachedTime > 0) {
tooltip.add(new TranslatableText(getTranslationKey() + ".tagline", ChatUtil.ticksToString(attachedTime)));
}
}
}
@Override
public Text getName(ItemStack stack) {
if (!stack.hasTag()) {
stack.setTag(new CompoundTag());
}
CompoundTag compound = stack.getTag();
int hideFlags = 0;
if (!compound.containsKey("HideFlags") || ((hideFlags = compound.getInt("HideFlags")) & 2) == 0) {
compound.putInt("HideFlags", hideFlags | 2);
}
return super.getName(stack);
}
@Override
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
if (!(entity instanceof PlayerEntity)) {
return;
}
PlayerEntity player = (PlayerEntity)entity;
if (player.getHealth() < player.getHealthMaximum()) {
player.heal(0.5F);
} else if (player.canConsume(false)) {
player.getHungerManager().add(1, 0);
}
IPlayer iplayer = SpeciesList.instance().getPlayer(player);
float attachedTime = iplayer.getInventory().getTicksAttached(this);
if (iplayer.getExertion() < 1) {
iplayer.addExertion(2);
}
if (iplayer.getEnergy() < 0.005F + (attachedTime / 1000000)) {
iplayer.addEnergy(2);
}
if (attachedTime == 1) {
world.playSound(null, player.getBlockPos(), SoundEvents.ENTITY_ELDER_GUARDIAN_CURSE, SoundCategory.PLAYERS, 3, 1);
}
if (attachedTime > 0 && attachedTime % 100 == 0) {
world.playSound(null, player.getBlockPos(), SoundEvents.MUSIC_NETHER, SoundCategory.PLAYERS, 3, 1);
}
if (attachedTime > 1000) {
if (world.random.nextInt(700) == 0) {
player.dropSelectedItem(false);
}
}
if (attachedTime > 3000) {
if (world.random.nextInt(300) == 0) {
player.addVelocity(world.random.nextFloat() - 0.5F, 0, 0);
}
if (world.random.nextInt(300) == 0) {
player.addVelocity(0, 0, world.random.nextFloat() - 0.5F);
}
}
if (attachedTime > 6000) {
if (world.random.nextInt(300) == 0) {
player.yaw += 180;
}
}
if (attachedTime > 13000) {
if (world.random.nextInt(300) == 0) {
player.damage(MagicalDamageSource.ALICORN_AMULET, 1F);
}
}
if (stack.getDamage() >= getMaxDamage() - 1) {
stack.damage(10, player, p -> p.sendEquipmentBreakStatus(EquipmentSlot.CHEST));
player.damage(MagicalDamageSource.ALICORN_AMULET, player.getHealthMaximum() - 0.01F);
player.getHungerManager().setFoodLevel(1);
Vec3d pos = player.getPos();
player.world.createExplosion(player, pos.x, pos.y, pos.z, 10, DestructionType.NONE);
UWorld.scheduleTask(w -> {
w.createExplosion(player, pos.x, pos.y, pos.z, 6, DestructionType.BREAK);
}, 50);
}
iplayer.getInventory().enforceDependency(this);
}
@Override
public void onRemoved(IPlayer player, float needfulness) {
float attachedTime = player.getInventory().getTicksAttached(this) / 100F;
LocalDifficulty difficulty = player.getWorld().getLocalDifficulty(player.getOrigin());
float amount = (attachedTime * (1 + needfulness)) * (1 + difficulty.getClampedLocalDifficulty());
amount = Math.min(amount, player.getOwner().getHealthMaximum());
player.getOwner().damage(MagicalDamageSource.ALICORN_AMULET, amount);
if (attachedTime > 120) {
player.getOwner().takeKnockback(player.getOwner(), 1, 1, 1);
}
}
@Override
public Multimap<String, EntityAttributeModifier> getModifiers(EquipmentSlot equipmentSlot) {
Multimap<String, EntityAttributeModifier> multimap = super.getModifiers(equipmentSlot);
if (equipmentSlot == slot) {
UUID modifierId = MODIFIERS[equipmentSlot.getEntitySlotId()];
multimap.put(EntityAttributes.ATTACK_DAMAGE.getId(), new EntityAttributeModifier(modifierId, "Strength modifier", 50, EntityAttributeModifier.Operation.ADDITION));
}
return multimap;
}
static class Material implements ArmorMaterial {
@Override
public int getDurability(EquipmentSlot slot) {
return 200;
}
@Override
public int getProtectionAmount(EquipmentSlot slot) {
return Integer.MAX_VALUE;
}
@Override
public int getEnchantability() {
return 0;
}
@Override
public SoundEvent getEquipSound() {
return SoundEvents.ITEM_ARMOR_EQUIP_IRON;
}
@Override
public Ingredient getRepairIngredient() {
return Ingredient.ofItems(UItems.alicorn_amulet);
}
@Override
public String getName() {
return "alicorn_amulet";
}
@Override
public float getToughness() {
return 20;
}
}
}

View file

@ -6,6 +6,8 @@ import java.util.function.Supplier;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.minelittlepony.unicopia.UItems; import com.minelittlepony.unicopia.UItems;
import com.minelittlepony.unicopia.ducks.IItemEntity;
import com.minelittlepony.unicopia.entity.capabilities.ItemEntityCapabilities;
import com.minelittlepony.unicopia.item.consumables.IEdible; import com.minelittlepony.unicopia.item.consumables.IEdible;
import com.minelittlepony.unicopia.item.consumables.Toxicity; import com.minelittlepony.unicopia.item.consumables.Toxicity;
import com.minelittlepony.util.collection.Pool; import com.minelittlepony.util.collection.Pool;
@ -23,10 +25,11 @@ import net.minecraft.particle.ParticleTypes;
import net.minecraft.tag.BlockTags; import net.minecraft.tag.BlockTags;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World; import net.minecraft.world.World;
public class AppleItem extends Item implements IEdible { public class AppleItem extends Item implements IEdible, ItemEntityCapabilities.TickableItem {
private static final Pool<Object, Weighted<Supplier<ItemStack>>> typeVariantMap = Pool.of(PlanksBlock.Type.OAK, private static final Pool<Object, Weighted<Supplier<ItemStack>>> typeVariantMap = Pool.of(PlanksBlock.Type.OAK,
PlanksBlock.Type.OAK, new Weighted<Supplier<ItemStack>>() PlanksBlock.Type.OAK, new Weighted<Supplier<ItemStack>>()
@ -71,38 +74,39 @@ public class AppleItem extends Item implements IEdible {
} }
@Override @Override
public boolean onEntityItemUpdate(ItemEntity item) { public ActionResult onGroundTick(IItemEntity item) {
ItemEntity entity = item.getRaceContainer().getOwner();
if (!item.removed && item.age > item.pickupDelay) { if (!entity.removed && item.getAge() > item.getPickupDelay()) {
if (!item.world.isClient) { if (!entity.world.isClient) {
item.remove(); entity.remove();
ItemEntity neu = EntityType.ITEM.create(item.world); ItemEntity neu = EntityType.ITEM.create(entity.world);
neu.copyPositionAndRotation(item); neu.copyPositionAndRotation(entity);
neu.setStack(new ItemStack(UItems.rotten_apple)); neu.setStack(new ItemStack(UItems.rotten_apple));
item.world.spawnEntity(neu); entity.world.spawnEntity(neu);
ItemEntity copy = EntityType.ITEM.create(item.world); ItemEntity copy = EntityType.ITEM.create(entity.world);
copy.copyPositionAndRotation(item); copy.copyPositionAndRotation(entity);
copy.setStack(item.getStack()); copy.setStack(entity.getStack());
copy.getStack().decrement(1); copy.getStack().decrement(1);
item.world.spawnEntity(copy); entity.world.spawnEntity(copy);
} else { } else {
float bob = MathHelper.sin(((float)item.getAge() + 1) / 10F + item.hoverHeight) * 0.1F + 0.1F; float bob = MathHelper.sin(((float)item.getAge() + 1) / 10F + entity.hoverHeight) * 0.1F + 0.1F;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
item.world.addParticle(ParticleTypes.AMBIENT_ENTITY_EFFECT, item.x, item.y + bob, item.z, entity.world.addParticle(ParticleTypes.AMBIENT_ENTITY_EFFECT, entity.x, entity.y + bob, entity.z,
item.world.random.nextGaussian() - 0.5F, entity.world.random.nextGaussian() - 0.5F,
item.world.random.nextGaussian() - 0.5F, entity.world.random.nextGaussian() - 0.5F,
item.world.random.nextGaussian() - 0.5F); entity.world.random.nextGaussian() - 0.5F);
} }
} }
} }
return false; return ActionResult.PASS;
} }
@Override @Override

View file

@ -0,0 +1,153 @@
package com.minelittlepony.unicopia.item;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.EquinePredicates;
import com.minelittlepony.unicopia.UContainers;
import com.minelittlepony.unicopia.inventory.gui.InventoryOfHolding;
import com.minelittlepony.unicopia.magic.Affinity;
import com.minelittlepony.unicopia.magic.items.IMagicalItem;
import com.minelittlepony.util.VecHelper;
import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.container.Container;
import net.minecraft.container.NameableContainerProvider;
import net.minecraft.entity.Entity;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult;
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.Box;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class BagOfHoldingItem extends Item implements IMagicalItem {
public BagOfHoldingItem() {
super(new Settings().maxCount(1).group(ItemGroup.TRANSPORTATION));
}
@Override
public void appendTooltip(ItemStack stack, @Nullable World worldIn, List<Text> tooltip, TooltipContext flagIn) {
super.appendTooltip(stack, worldIn, tooltip, flagIn);
Map<Text, Integer> counts = new HashMap<>();
InventoryOfHolding.iterateContents(stack, (i, itemstack) -> {
Text name = itemstack.getName();
counts.put(name, counts.getOrDefault(name, 0) + itemstack.getCount());
return true;
});
for (Text name : counts.keySet()) {
tooltip.add(name.append(" ").append(counts.get(name).toString()));
}
}
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
if (!EquinePredicates.MAGI.test(player)) {
return super.use(world, player, hand);
}
ItemStack stack = player.getStackInHand(hand);
if (player.isSneaking()) {
HitResult hit = VecHelper.getObjectMouseOver(player, 5, 0);
if (hit != null) {
if (hit.getType() == HitResult.Type.BLOCK) {
BlockHitResult bhit = (BlockHitResult)hit;
BlockPos pos = bhit.getBlockPos();
BlockEntity tile = world.getBlockEntity(pos);
if (tile instanceof Inventory) {
InventoryOfHolding inventory = InventoryOfHolding.getInventoryFromStack(stack);
inventory.addBlockEntity(world, pos, (BlockEntity & Inventory)tile);
inventory.writeTostack(stack);
inventory.onInvClose(player);
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
}
Box box = new Box(pos.offset(bhit.getSide())).expand(0.5);
List<Entity> itemsAround = world.getEntities(player, box, EquinePredicates.ITEMS);
if (itemsAround.size() > 0) {
InventoryOfHolding inventory = InventoryOfHolding.getInventoryFromStack(stack);
inventory.addItem((ItemEntity)itemsAround.get(0));
inventory.writeTostack(stack);
inventory.onInvClose(player);
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
}
}
}
return new TypedActionResult<>(ActionResult.FAIL, stack);
}
ContainerProviderRegistry.INSTANCE.openContainer(UContainers.BAG_OF_HOLDING, player, o -> {});
player.openContainer(new ContainerProvider(stack));
player.playSound(SoundEvents.BLOCK_ENDER_CHEST_OPEN, 0.5F, 1);
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
}
@Override
public Affinity getAffinity() {
return Affinity.NEUTRAL;
}
@Override
public boolean hasInnerSpace() {
return true;
}
class ContainerProvider implements NameableContainerProvider {
private Text customname = null;
ContainerProvider(ItemStack stack) {
if (stack.hasCustomName()) {
customname = stack.getName();
}
}
@Override
public Text getDisplayName() {
if (customname != null) {
return customname;
}
return new TranslatableText("unicopi.gui.title.itemofholding");
}
@Override
public Container createMenu(int id, PlayerInventory playerInventory, PlayerEntity player) {
return null;
}
}
}

View file

@ -1,11 +1,10 @@
package com.minelittlepony.unicopia.item; package com.minelittlepony.unicopia.item;
import java.util.function.Function;
import com.minelittlepony.unicopia.entity.CloudEntity; import com.minelittlepony.unicopia.entity.CloudEntity;
import com.minelittlepony.unicopia.magic.items.IDispensable; import com.minelittlepony.unicopia.magic.items.IDispensable;
import net.minecraft.block.DispenserBlock; import net.minecraft.block.DispenserBlock;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemGroup;
@ -23,20 +22,20 @@ import net.minecraft.world.World;
public class CloudPlacerItem extends Item implements IDispensable { public class CloudPlacerItem extends Item implements IDispensable {
private final Function<World, CloudEntity> cloudSupplier; private final EntityType<? extends CloudEntity> cloudSupplier;
public CloudPlacerItem(Function<World, CloudEntity> cloudSupplier) { public CloudPlacerItem(EntityType<? extends CloudEntity> spawner) {
super(new Item.Settings() super(new Item.Settings()
.group(ItemGroup.MATERIALS) .group(ItemGroup.MATERIALS)
.maxCount(16) .maxCount(16)
); );
this.cloudSupplier = cloudSupplier; this.cloudSupplier = spawner;
setDispenseable(); setDispenseable();
} }
public void placeCloud(World world, BlockPos pos) { public void placeCloud(World world, BlockPos pos) {
CloudEntity cloud = cloudSupplier.apply(world); CloudEntity cloud = cloudSupplier.create(world);
cloud.setPositionAndAngles(pos, 0, 0); cloud.setPositionAndAngles(pos, 0, 0);
world.spawnEntity(cloud); world.spawnEntity(cloud);
} }

View file

@ -3,7 +3,7 @@ package com.minelittlepony.unicopia.item;
import com.minelittlepony.unicopia.magic.Affinity; import com.minelittlepony.unicopia.magic.Affinity;
import com.minelittlepony.unicopia.magic.IDispenceable; import com.minelittlepony.unicopia.magic.IDispenceable;
import com.minelittlepony.unicopia.magic.IMagicEffect; import com.minelittlepony.unicopia.magic.IMagicEffect;
import com.minelittlepony.unicopia.magic.spells.SpellCastResult; import com.minelittlepony.unicopia.magic.spells.CastResult;
import com.minelittlepony.util.MagicalDamageSource; import com.minelittlepony.util.MagicalDamageSource;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -16,20 +16,20 @@ import net.minecraft.world.explosion.Explosion.DestructionType;
public class CursedMagicGemItem extends MagicGemItem { public class CursedMagicGemItem extends MagicGemItem {
@Override @Override
public SpellCastResult onDispenseSpell(BlockPointer source, ItemStack stack, IDispenceable effect) { public CastResult onDispenseSpell(BlockPointer source, ItemStack stack, IDispenceable effect) {
BlockPos pos = source.getBlockPos(); BlockPos pos = source.getBlockPos();
World world = source.getWorld(); World world = source.getWorld();
SpellCastResult result = super.onDispenseSpell(source, stack, effect); CastResult result = super.onDispenseSpell(source, stack, effect);
if (result != SpellCastResult.NONE) { if (result != CastResult.NONE) {
if (world.random.nextInt(200) == 0) { if (world.random.nextInt(200) == 0) {
float strength = world.random.nextFloat() * 100; float strength = world.random.nextFloat() * 100;
world.createExplosion(null, pos.getX(), pos.getY(), pos.getZ(), strength, DestructionType.DESTROY); world.createExplosion(null, pos.getX(), pos.getY(), pos.getZ(), strength, DestructionType.DESTROY);
return SpellCastResult.NONE; return CastResult.NONE;
} }
} }
@ -37,10 +37,10 @@ public class CursedMagicGemItem extends MagicGemItem {
} }
@Override @Override
public SpellCastResult onCastSpell(ItemUsageContext context, IMagicEffect effect) { public CastResult onCastSpell(ItemUsageContext context, IMagicEffect effect) {
SpellCastResult result = super.onCastSpell(context, effect); CastResult result = super.onCastSpell(context, effect);
if (result != SpellCastResult.NONE) { if (result != CastResult.NONE) {
context.getPlayer().damage(MagicalDamageSource.causePlayerDamage("corruption", context.getPlayer()), 1); context.getPlayer().damage(MagicalDamageSource.causePlayerDamage("corruption", context.getPlayer()), 1);
} }

View file

@ -0,0 +1,152 @@
package com.minelittlepony.unicopia.item;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.EquinePredicates;
import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.entity.capabilities.IPlayer;
import com.minelittlepony.unicopia.magic.Affinity;
import com.minelittlepony.unicopia.magic.CasterUtils;
import com.minelittlepony.unicopia.magic.IAffine;
import com.minelittlepony.unicopia.magic.ICaster;
import com.minelittlepony.unicopia.magic.ITossedEffect;
import com.minelittlepony.unicopia.projectile.ITossableItem;
import net.minecraft.block.BlockState;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
public class EnchantedStaffItem extends StaffItem implements IAffine, ITossableItem {
@Nonnull
private final ITossedEffect effect;
public EnchantedStaffItem(Settings settings, @Nonnull ITossedEffect effect) {
super(settings.maxDamage(500));
this.effect = effect;
}
@Override
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
tooltip.add(getAffinity().getName());
}
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
if (EquinePredicates.MAGI.test(player) && hand == Hand.MAIN_HAND) {
ItemStack itemstack = player.getStackInHand(hand);
player.swingHand(hand);
return new TypedActionResult<>(ActionResult.SUCCESS, itemstack);
}
return super.use(world, player, hand);
}
@Override
public void onStoppedUsing(ItemStack itemstack, World world, LivingEntity entity, int timeLeft) {
if (EquinePredicates.MAGI.test(entity) && entity instanceof PlayerEntity) {
int i = getMaxUseTime(itemstack) - timeLeft;
if (i > 10 && canBeThrown(itemstack)) {
toss(world, itemstack, (PlayerEntity)entity);
}
}
}
@Override
protected boolean castContainedEffect(ItemStack stack, LivingEntity target, LivingEntity attacker) {
if (attacker.isSneaking()) {
stack.damage(50, attacker, p -> p.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND));
CasterUtils.toCaster(attacker).ifPresent(c -> c.subtractEnergyCost(4));
CasterUtils.toCaster(target).ifPresent(c -> onImpact(
c,
target.getBlockPos(),
target.getEntityWorld().getBlockState(target.getBlockPos())
));
return true;
}
return false;
}
public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) {
if (entity instanceof LivingEntity) {
LivingEntity living = (LivingEntity)entity;
if (living.getActiveItem().getItem() == this) {
Vec3d eyes = entity.getCameraPosVec(1);
float i = getMaxUseTime(stack) - living.getItemUseTimeLeft();
world.addParticle(i > 150 ? ParticleTypes.LARGE_SMOKE : ParticleTypes.CLOUD, eyes.x, eyes.y, eyes.z,
(world.random.nextGaussian() - 0.5) / 10,
(world.random.nextGaussian() - 0.5) / 10,
(world.random.nextGaussian() - 0.5) / 10
);
world.playSound(null, entity.getBlockPos(), SoundEvents.ENTITY_GUARDIAN_ATTACK, SoundCategory.PLAYERS, 1, i / 20);
if (i > 200) {
living.clearActiveItem();
living.damage(DamageSource.MAGIC, 1200);
CasterUtils.toCaster(entity).ifPresent(c -> onImpact(
c,
entity.getBlockPos(),
entity.getEntityWorld().getBlockState(entity.getBlockPos())
));
}
}
}
}
@Override
public int getMaxUseTime(ItemStack stack) {
return 72000;
}
@Override
public void toss(World world, ItemStack stack, PlayerEntity player) {
IPlayer iplayer = SpeciesList.instance().getPlayer(player);
iplayer.subtractEnergyCost(4);
effect.toss(iplayer);
stack.damage(1, player, p -> p.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND));
}
@Override
public void onImpact(ICaster<?> caster, BlockPos pos, BlockState state) {
effect.onImpact(caster, pos, state);
}
@Override
public Affinity getAffinity() {
return effect.getAffinity();
}
}

View file

@ -1,262 +0,0 @@
package com.minelittlepony.unicopia.item;
import java.util.List;
import java.util.UUID;
import javax.annotation.Nullable;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.UClient;
import com.minelittlepony.unicopia.entity.capabilities.IPlayer;
import com.minelittlepony.unicopia.magic.items.IDependable;
import com.minelittlepony.unicopia.spell.SpellAffinity;
import com.minelittlepony.unicopia.world.UWorld;
import com.minelittlepony.util.MagicalDamageSource;
import com.minelittlepony.util.VecHelper;
import com.minelittlepony.util.lang.ClientLocale;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity;
import net.minecraft.entity.MoverType;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.ActionResult;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.StringUtils;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.World;
public class ItemAlicornAmulet extends ItemArmor implements IDependable {
public static final DamageSource DAMAGE_SOURCE = MagicalDamageSource.create("alicorn_amulet")
.setDamageBypassesArmor()
.setDamageIsAbsolute();
private static final UUID[] ARMOR_MODIFIERS = new UUID[] {
UUID.fromString("845DB27C-C624-495F-8C9F-6020A9A58B6B"),
UUID.fromString("D8499B04-0E66-4726-AB29-64469D734E0D"),
UUID.fromString("9F3D476D-C118-4544-8365-64846904B48E"),
UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150")
};
public ItemAlicornAmulet(String domain, String name) {
super(ArmorMaterial.GOLD, 1, EntityEquipmentSlot.CHEST);
setTranslationKey(name);
setRegistryName(domain, name);
}
@Override
public SpellAffinity getAffinity() {
return SpellAffinity.BAD;
}
@Override
public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) {
return toRepair.getItem() == repair.getItem();
}
@Override
public boolean onEntityItemUpdate(EntityItem entity) {
World world = entity.world;
double x = entity.posX + world.rand.nextFloat() - 0.5;
double z = entity.posZ + world.rand.nextFloat() - 0.5;
double y = entity.posY + world.rand.nextFloat();
EnumParticleTypes particle = world.rand.nextBoolean() ? EnumParticleTypes.SMOKE_LARGE : EnumParticleTypes.FLAME;
world.spawnParticle(particle, x, y, z, 0, 0, 0);
if (world.rand.nextInt(500) == 0) {
world.playSound(null, entity.getPosition(), SoundEvents.AMBIENT_CAVE, SoundCategory.HOSTILE, 0.5F, 1);
}
Vec3d position = entity.getPositionVector();
VecHelper.findAllEntitiesInRange(entity, world, entity.getPosition(), 10)
.filter(e -> e instanceof PlayerEntity)
.sorted((a, b) -> (int)(a.getPositionVector().distanceTo(position) - b.getPositionVector().distanceTo(position)))
.findFirst()
.ifPresent(player -> interactWithPlayer(entity, (PlayerEntity)player));
return false;
}
protected void interactWithPlayer(EntityItem entity, PlayerEntity player) {
double diffX = player.posX - entity.posX;
double diffY = player.posY - entity.posY;
double diffZ = player.posZ - entity.posZ;
entity.move(MoverType.SELF, diffX / 50, diffY / 50, diffZ / 50);
if (!player.world.isClient && !entity.isDead) {
if (player.getPositionVector().distanceTo(entity.getPositionVector()) < 3) {
if (entity.world.rand.nextInt(150) == 0) {
TypedActionResult<ItemStack> result = onItemRightClick(player.world, player, EnumHand.MAIN_HAND);
if (result.getType() == EnumActionResult.SUCCESS) {
entity.setPickupDelay(1000);
entity.setDead();
}
}
}
}
}
@Override
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
IPlayer iplayer = UClient.instance().getIPlayer();
if (iplayer != null) {
int attachedTime = iplayer.getInventory().getTicksAttached(this);
if (attachedTime > 0) {
tooltip.add(ClientLocale.format(getTranslationKey() + ".tagline", StringUtils.ticksToElapsedTime(attachedTime)));
}
}
}
@Override
public String getItemStackDisplayName(ItemStack stack) {
if (!stack.hasTagCompound()) {
stack.setTagCompound(new CompoundTag());
}
CompoundTag compound = stack.getTagCompound();
int hideFlags = 0;
if (!compound.hasKey("HideFlags") || ((hideFlags = compound.getInteger("HideFlags")) & 2) == 0) {
compound.setInteger("HideFlags", hideFlags | 2);
}
return super.getItemStackDisplayName(stack);
}
@Override
public void onArmorTick(World world, PlayerEntity player, ItemStack itemStack) {
if (player.getHealth() < player.getMaxHealth()) {
player.heal(0.5F);
} else if (player.canEat(false)) {
player.getFoodStats().addStats(1, 0);
}
IPlayer iplayer = SpeciesList.instance().getPlayer(player);
float attachedTime = iplayer.getInventory().getTicksAttached(this);
if (iplayer.getExertion() < 1) {
iplayer.addExertion(2);
}
if (iplayer.getEnergy() < 0.005F + (attachedTime / 1000000)) {
iplayer.addEnergy(2);
}
if (attachedTime == 1) {
world.playSound(null, player.getPosition(), SoundEvents.ENTITY_ELDER_GUARDIAN_CURSE, SoundCategory.PLAYERS, 3, 1);
}
if (attachedTime > 0 && attachedTime % 100 == 0) {
world.playSound(null, player.getPosition(), SoundEvents.MUSIC_NETHER, SoundCategory.PLAYERS, 3, 1);
}
if (attachedTime > 1000) {
if (world.rand.nextInt(700) == 0) {
player.dropItem(false);
}
}
if (attachedTime > 3000) {
if (world.rand.nextInt(300) == 0) {
player.motionX += world.rand.nextFloat() - 0.5F;
}
if (world.rand.nextInt(300) == 0) {
player.motionZ += world.rand.nextFloat() - 0.5F;
}
}
if (attachedTime > 6000) {
if (world.rand.nextInt(300) == 0) {
player.rotationYaw += 180;
}
}
if (attachedTime > 13000) {
if (world.rand.nextInt(300) == 0) {
player.attackEntityFrom(DAMAGE_SOURCE, 1F);
}
}
if (itemStack.getItemDamage() >= getMaxDamage(itemStack) - 1) {
itemStack.damageItem(10, player);
player.attackEntityFrom(DAMAGE_SOURCE, player.getMaxHealth() - 0.01F);
player.getFoodStats().setFoodLevel(1);
Vec3d pos = player.getPositionVector();
player.world.newExplosion(player, pos.x, pos.y, pos.z, 10, false, false);
UWorld.scheduleTask(w -> {
w.newExplosion(player, pos.x, pos.y, pos.z, 6, false, true);
}, 50);
}
iplayer.getInventory().enforceDependency(this);
}
@Override
public void onRemoved(IPlayer player, float needfulness) {
float attachedTime = player.getInventory().getTicksAttached(this) / 100F;
DifficultyInstance difficulty = player.getWorld().getDifficultyForLocation(player.getOrigin());
float amount = (attachedTime * (1 + needfulness)) * (1 + difficulty.getClampedAdditionalDifficulty());
amount = Math.min(amount, player.getOwner().getMaxHealth());
player.getOwner().attackEntityFrom(DAMAGE_SOURCE, amount);
if (attachedTime > 120) {
player.getOwner().knockBack(player.getOwner(), 1, 1, 1);
}
}
@Override
public String getArmorTexture(ItemStack stack, Entity entity, EntityEquipmentSlot slot, String type) {
return "unicopia:textures/models/armor/alicorn_amulet.png";
}
@Override
public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot) {
Multimap<String, AttributeModifier> multimap = HashMultimap.create();;
if (equipmentSlot == armorType) {
UUID modifierId = ARMOR_MODIFIERS[equipmentSlot.getIndex()];
multimap.put(SharedMonsterAttributes.ARMOR.getName(), new AttributeModifier(modifierId, "Armor modifier", Integer.MAX_VALUE, 0));
multimap.put(SharedMonsterAttributes.ARMOR_TOUGHNESS.getName(), new AttributeModifier(modifierId, "Armor toughness", 20, 0));
multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(modifierId, "Strength modifier", 50, 0));
}
return multimap;
}
}

View file

@ -1,81 +0,0 @@
package com.minelittlepony.unicopia.item;
import com.minelittlepony.unicopia.forgebullshit.IMultiItem;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
public class ItemAppleMultiType extends AppleItem implements IMultiItem {
private String[] subTypes = new String[0];
private String[] variants = subTypes;
public ItemAppleMultiType(String domain, String name) {
super(domain, name);
}
public ItemAppleMultiType setSubTypes(String... types) {
setHasSubtypes(types.length > 0);
setMaxDamage(0);
subTypes = types;
variants = new String[types.length];
setTranslationKey(variants[0] = types[0]);
for (int i = 1; i < variants.length; i++) {
variants[i] = variants[0] + "_" + types[i % types.length];
}
return this;
}
@Override
public String[] getVariants() {
return variants;
}
protected String[] getSubTypes() {
return subTypes;
}
@Override
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items) {
if (isInCreativeTab(tab)) {
items.add(new ItemStack(this, 1, 0));
for (int i = 1; i < getSubTypes().length; i++) {
items.add(new ItemStack(this, 1, i));
}
}
}
@Override
public int getMetadata(ItemStack stack) {
if (getHasSubtypes()) {
return super.getMetadata(stack) % getSubTypes().length;
}
return super.getMetadata(stack);
}
@Override
public boolean onEntityItemUpdate(EntityItem item) {
return false;
}
@Override
public String getTranslationKey(ItemStack stack) {
if (getHasSubtypes()) {
int meta = Math.max(0, stack.getMetadata() % getSubTypes().length);
if (meta > 0) {
return super.getTranslationKey(stack) + "." + getSubTypes()[meta];
}
}
return super.getTranslationKey(stack);
}
}

View file

@ -1,44 +0,0 @@
package com.minelittlepony.unicopia.item;
import com.minelittlepony.unicopia.SpeciesList;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.init.Items;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public class ItemCereal extends ItemFood {
private int sugarAmount;
public ItemCereal(String domain, String name, int amount, float saturation) {
super(amount, saturation, false);
setTranslationKey(name);
setRegistryName(domain, name);
setMaxStackSize(1);
setContainerItem(Items.BOWL);
}
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, LivingEntity entityLiving) {
super.onItemUseFinish(stack, worldIn, entityLiving);
return getContainerItem(stack);
}
@Override
protected void onFoodEaten(ItemStack stack, World worldIn, PlayerEntity player) {
super.onFoodEaten(stack, worldIn, player);
if (sugarAmount != 0) {
SpeciesList.instance().getPlayer(player).addEnergy(sugarAmount);
}
}
public ItemCereal setSugarAmount(int sugar) {
sugarAmount = sugar;
return this;
}
}

View file

@ -1,156 +0,0 @@
package com.minelittlepony.unicopia.item;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.EquinePredicates;
import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.entity.capabilities.IPlayer;
import com.minelittlepony.unicopia.projectile.ITossableItem;
import com.minelittlepony.unicopia.spell.CasterUtils;
import com.minelittlepony.unicopia.spell.IAligned;
import com.minelittlepony.unicopia.spell.ICaster;
import com.minelittlepony.unicopia.spell.ITossedEffect;
import com.minelittlepony.unicopia.spell.SpellAffinity;
import com.minelittlepony.util.lang.ClientLocale;
import net.minecraft.block.state.BlockState;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
public class ItemMagicStaff extends ItemStaff implements IAligned, ITossableItem {
@Nonnull
private final ITossedEffect effect;
public ItemMagicStaff(String domain, String name, @Nonnull ITossedEffect effect) {
super(domain, name);
this.effect = effect;
setMaxDamage(500);
}
@Override
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
SpellAffinity affinity = getAffinity();
tooltip.add(affinity.getColourCode() + ClientLocale.format(affinity.getUnlocalizedName()));
}
@Override
public TypedActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, EnumHand hand) {
if (EquinePredicates.MAGI.test(player) && hand == EnumHand.MAIN_HAND) {
ItemStack itemstack = player.getStackInHand(hand);
player.setActiveHand(hand);
return new TypedActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
}
return super.onItemRightClick(world, player, hand);
}
@Override
public void onPlayerStoppedUsing(ItemStack itemstack, World world, LivingEntity entity, int timeLeft) {
if (EquinePredicates.MAGI.test(entity) && entity instanceof PlayerEntity) {
int i = getMaxItemUseDuration(itemstack) - timeLeft;
if (i > 10) {
if (canBeThrown(itemstack)) {
toss(world, itemstack, (PlayerEntity)entity);
}
}
}
}
@Override
protected boolean castContainedEffect(ItemStack stack, LivingEntity target, LivingEntity attacker) {
if (attacker.isSneaking()) {
stack.damageItem(50, attacker);
CasterUtils.toCaster(attacker).ifPresent(c -> c.subtractEnergyCost(4));
onImpact(
CasterUtils.near(target),
target.getPosition(),
target.getEntityWorld().getBlockState(target.getPosition())
);
return true;
}
return false;
}
public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) {
if (entity instanceof LivingEntity) {
LivingEntity living = (LivingEntity)entity;
if (living.getActiveItemStack().getItem() == this) {
Vec3d eyes = entity.getPositionEyes(1);
float i = getMaxItemUseDuration(stack) - living.getItemInUseCount();
world.spawnParticle(i > 150 ? EnumParticleTypes.SMOKE_LARGE : EnumParticleTypes.CLOUD, eyes.x, eyes.y, eyes.z,
(world.rand.nextGaussian() - 0.5) / 10,
(world.rand.nextGaussian() - 0.5) / 10,
(world.rand.nextGaussian() - 0.5) / 10
);
world.playSound(null, entity.getPosition(), SoundEvents.ENTITY_GUARDIAN_ATTACK, SoundCategory.PLAYERS, 1, i / 20);
if (i > 200) {
living.resetActiveHand();
living.attackEntityFrom(DamageSource.MAGIC, 1200);
onImpact(
CasterUtils.toCaster(entity).orElseGet(() -> CasterUtils.near(entity)),
entity.getPosition(),
entity.getEntityWorld().getBlockState(entity.getPosition())
);
}
}
}
}
@Override
public int getMaxItemUseDuration(ItemStack stack) {
return 72000;
}
@Override
public void toss(World world, ItemStack stack, PlayerEntity player) {
IPlayer iplayer = SpeciesList.instance().getPlayer(player);
iplayer.subtractEnergyCost(4);
effect.toss(iplayer);
stack.damageItem(1, player);
}
@Override
public void onImpact(ICaster<?> caster, BlockPos pos, BlockState state) {
effect.onImpact(caster, pos, state);
}
@Override
public SpellAffinity getAffinity() {
return effect.getAffinity();
}
}

View file

@ -1,174 +0,0 @@
package com.minelittlepony.unicopia.item;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.EquinePredicates;
import com.minelittlepony.unicopia.UClient;
import com.minelittlepony.unicopia.inventory.gui.ContainerOfHolding;
import com.minelittlepony.unicopia.inventory.gui.InventoryOfHolding;
import com.minelittlepony.unicopia.magic.items.IMagicalItem;
import com.minelittlepony.unicopia.spell.SpellAffinity;
import com.minelittlepony.util.VecHelper;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.IInteractionObject;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemOfHolding extends Item implements IMagicalItem {
public ItemOfHolding(String domain, String name) {
setCreativeTab(CreativeTabs.TRANSPORTATION);
setTranslationKey(name);
setRegistryName(domain, name);
setMaxStackSize(1);
}
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
super.addInformation(stack, worldIn, tooltip, flagIn);
Map<String, Integer> counts = new HashMap<>();
InventoryOfHolding.iterateContents(stack, (i, itemstack) -> {
String name = itemstack.getDisplayName();
counts.put(name, counts.getOrDefault(name, 0) + itemstack.getCount());
return true;
});
for (String name : counts.keySet()) {
tooltip.add(String.format("%s x%d", name, counts.get(name)));
}
}
@Override
public TypedActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, EnumHand hand) {
if (!EquinePredicates.MAGI.test(player)) {
return super.onItemRightClick(world, player, hand);
}
ItemStack stack = player.getStackInHand(hand);
if (player.isSneaking()) {
RayTraceResult hit = VecHelper.getObjectMouseOver(player, 5, 0);
if (hit != null) {
if (hit.typeOfHit == RayTraceResult.Type.BLOCK) {
BlockPos pos = hit.getBlockPos();
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof IInventory) {
InventoryOfHolding inventory = InventoryOfHolding.getInventoryFromStack(stack);
inventory.addBlockEntity(world, pos, (TileEntity & IInventory)tile);
inventory.writeTostack(stack);
inventory.closeInventory(player);
return new TypedActionResult<>(EnumActionResult.SUCCESS, stack);
}
Box box = new Box(pos.offset(hit.sideHit)).grow(0.5);
List<Entity> itemsAround = world.getEntitiesInAABBexcluding(player, box, EquinePredicates.ITEMS);
if (itemsAround.size() > 0) {
InventoryOfHolding inventory = InventoryOfHolding.getInventoryFromStack(stack);
inventory.addItem((EntityItem)itemsAround.get(0));
inventory.writeTostack(stack);
inventory.closeInventory(player);
return new TypedActionResult<>(EnumActionResult.SUCCESS, stack);
}
}
}
return new TypedActionResult<>(EnumActionResult.FAIL, stack);
}
UClient.instance().displayGuiToPlayer(player, new Inventory(stack));
player.playSound(SoundEvents.BLOCK_ENDERCHEST_OPEN, 0.5F, 1);
return new TypedActionResult<>(EnumActionResult.SUCCESS, stack);
}
@Override
public SpellAffinity getAffinity() {
return SpellAffinity.NEUTRAL;
}
@Override
public boolean hasInnerSpace() {
return true;
}
public class Inventory implements IInteractionObject {
private String customname = null;
Inventory(ItemStack stack) {
if (stack.hasDisplayName()) {
customname = stack.getDisplayName();
}
}
@Override
public String getName() {
return "unicopi.gui.title.itemofholding";
}
@Override
public boolean hasCustomName() {
return customname != null;
}
@Override
public ITextComponent getDisplayName() {
if (hasCustomName()) {
return new TextComponentString(customname);
}
return new TextComponentTranslation(getName());
}
@Override
public Container createContainer(InventoryPlayer playerInventory, PlayerEntity player) {
return new ContainerOfHolding(player);
}
@Override
public String getGuiID() {
return "unicopia:itemofholding";
}
}
}

View file

@ -1,108 +0,0 @@
package com.minelittlepony.unicopia.item;
import java.util.List;
import java.util.UUID;
import javax.annotation.Nullable;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.minelittlepony.unicopia.EquinePredicates;
import com.minelittlepony.util.lang.ClientLocale;
import net.minecraft.block.Block;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
public class ItemStaff extends ItemSword {
protected static final UUID ATTACK_REACH_MODIFIER = UUID.fromString("FA235E1C-4280-A865-B01B-CBAE9985ACA3");
public ItemStaff(String domain, String name) {
super(ToolMaterial.WOOD);
setTranslationKey(name);
setRegistryName(domain, name);
setMaxStackSize(1);
}
@Override
public boolean onLeftClickEntity(ItemStack stack, PlayerEntity player, Entity target) {
World w = player.getEntityWorld();
for (int i = 0; i < 130; i++) {
w.spawnParticle(EnumParticleTypes.BLOCK_CRACK,
target.posX + (target.world.rand.nextFloat() - 0.5F) * (target.width + 1),
(target.posY + target.height/2) + (target.world.rand.nextFloat() - 0.5F) * target.height,
target.posZ + (target.world.rand.nextFloat() - 0.5F) * (target.width + 1),
0, 0, 0,
Block.getStateId(Blocks.LOG.getDefaultState())
);
}
return false;
}
@Override
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
tooltip.add(ClientLocale.format(getTranslationKey(stack) + ".tagline"));
}
@Override
public boolean hitEntity(ItemStack stack, LivingEntity target, LivingEntity attacker) {
super.hitEntity(stack, target, attacker);
if (EquinePredicates.MAGI.test(attacker)) {
return castContainedEffect(stack, target, attacker);
}
return false;
}
protected boolean castContainedEffect(ItemStack stack, LivingEntity target, LivingEntity attacker) {
target.getEntityWorld().playSound(null, target.getPosition(), SoundEvents.ENTITY_PLAYER_ATTACK_CRIT, attacker.getSoundCategory(), 1, 1);
target.knockBack(attacker, 2,
MathHelper.sin(attacker.rotationYaw * 0.017453292F),
-MathHelper.cos(attacker.rotationYaw * 0.017453292F)
);
return true;
}
@Override
public boolean isFull3D() {
return true;
}
@Override
public EnumAction getItemUseAction(ItemStack stack) {
return EnumAction.BOW;
}
@Override
public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot slot) {
Multimap<String, AttributeModifier> multimap = HashMultimap.create();
if (slot == EntityEquipmentSlot.MAINHAND) {
multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", getAttackDamage(), 0));
multimap.put(PlayerEntity.REACH_DISTANCE.getName(), new AttributeModifier(ATTACK_REACH_MODIFIER, "Weapon modifier", 3, 0));
}
return multimap;
}
}

View file

@ -1,84 +0,0 @@
package com.minelittlepony.unicopia.item;
import com.minelittlepony.unicopia.item.consumables.Toxicity;
import com.minelittlepony.util.MagicalDamageSource;
import com.minelittlepony.util.VecHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LightningEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.DefaultedList;
import net.minecraft.world.World;
public class ItemZapApple extends ItemAppleMultiType {
public ItemZapApple(String domain, String name) {
super(domain, name);
setAlwaysEdible();
}
@Override
public TypedActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, EnumHand hand) {
RayTraceResult mop = VecHelper.getObjectMouseOver(player, 5, 0);
if (mop != null && mop.typeOfHit == RayTraceResult.Type.ENTITY) {
ItemStack stack = player.getStackInHand(hand);
if (canFeedTo(stack, mop.entityHit)) {
return onFedTo(stack, player, mop.entityHit);
}
}
return super.onItemRightClick(world, player, hand);
}
@Override
protected void onFoodEaten(ItemStack stack, World w, PlayerEntity player) {
super.onFoodEaten(stack, w, player);
player.attackEntityFrom(MagicalDamageSource.create("zap"), 120);
w.addWeatherEffect(new EntityLightningBolt(w, player.posX, player.posY, player.posZ, false));
}
public boolean canFeedTo(ItemStack stack, Entity e) {
return e instanceof EntityVillager
|| e instanceof EntityCreeper
|| e instanceof EntityPig;
}
public TypedActionResult<ItemStack> onFedTo(ItemStack stack, PlayerEntity player, Entity e) {
e.onStruckByLightning(new LightningEntity(e.world, e.posX, e.posY, e.posZ, false));
if (!player.capabilities.isCreativeMode) {
stack.shrink(1);
}
return new TypedActionResult<ItemStack>(ActionResult.SUCCESS, stack);
}
@Override
public void getSubItems(CreativeTabs tab, DefaultedList<ItemStack> items) {
if (isInCreativeTab(tab)) {
items.add(new ItemStack(this, 1, 0));
}
}
@Override
public Toxicity getToxicityLevel(ItemStack stack) {
return stack.getMetadata() == 0 ? Toxicity.SEVERE : Toxicity.SAFE;
}
@Override
public EnumRarity getRarity(ItemStack stack) {
int meta = stack.getMetadata();
if (meta == 0) {
return EnumRarity.EPIC;
}
return EnumRarity.RARE;
}
}

View file

@ -11,7 +11,7 @@ import com.minelittlepony.unicopia.magic.IDispenceable;
import com.minelittlepony.unicopia.magic.IMagicEffect; import com.minelittlepony.unicopia.magic.IMagicEffect;
import com.minelittlepony.unicopia.magic.IUseable; import com.minelittlepony.unicopia.magic.IUseable;
import com.minelittlepony.unicopia.magic.items.ICastable; import com.minelittlepony.unicopia.magic.items.ICastable;
import com.minelittlepony.unicopia.magic.spells.SpellCastResult; import com.minelittlepony.unicopia.magic.spells.CastResult;
import com.minelittlepony.unicopia.magic.spells.SpellRegistry; import com.minelittlepony.unicopia.magic.spells.SpellRegistry;
import com.minelittlepony.util.VecHelper; import com.minelittlepony.util.VecHelper;
@ -50,7 +50,7 @@ public class MagicGemItem extends Item implements ICastable {
} }
@Override @Override
public SpellCastResult onDispenseSpell(BlockPointer source, ItemStack stack, IDispenceable effect) { public CastResult onDispenseSpell(BlockPointer source, ItemStack stack, IDispenceable effect) {
Direction facing = source.getBlockState().get(DispenserBlock.FACING); Direction facing = source.getBlockState().get(DispenserBlock.FACING);
BlockPos pos = source.getBlockPos().offset(facing); BlockPos pos = source.getBlockPos().offset(facing);
@ -58,12 +58,12 @@ public class MagicGemItem extends Item implements ICastable {
} }
@Override @Override
public SpellCastResult onCastSpell(ItemUsageContext context, IMagicEffect effect) { public CastResult onCastSpell(ItemUsageContext context, IMagicEffect effect) {
if (effect instanceof IUseable) { if (effect instanceof IUseable) {
return ((IUseable)effect).onUse(context, getAffinity(context.getStack())); return ((IUseable)effect).onUse(context, getAffinity(context.getStack()));
} }
return SpellCastResult.PLACE; return CastResult.PLACE;
} }
@Override @Override
@ -89,17 +89,17 @@ public class MagicGemItem extends Item implements ICastable {
return ActionResult.FAIL; return ActionResult.FAIL;
} }
SpellCastResult result = onCastSpell(context, effect); CastResult result = onCastSpell(context, effect);
if (!context.getWorld().isClient) { if (!context.getWorld().isClient) {
pos = pos.offset(context.getSide()); pos = pos.offset(context.getSide());
if (result == SpellCastResult.PLACE) { if (result == CastResult.PLACE) {
castContainedSpell(context.getWorld(), pos, stack, effect).setOwner(player); castContainedSpell(context.getWorld(), pos, stack, effect).setOwner(player);
} }
} }
if (result != SpellCastResult.NONE) { if (result != CastResult.NONE) {
if (!player.isCreative()) { if (!player.isCreative()) {
stack.decrement(1); stack.decrement(1);
} }
@ -126,10 +126,10 @@ public class MagicGemItem extends Item implements ICastable {
IUseable effect = SpellRegistry.instance().getUseActionFrom(stack); IUseable effect = SpellRegistry.instance().getUseActionFrom(stack);
if (effect != null) { if (effect != null) {
SpellCastResult result = effect.onUse(stack, getAffinity(stack), player, world, VecHelper.getLookedAtEntity(player, 5)); CastResult result = effect.onUse(stack, getAffinity(stack), player, world, VecHelper.getLookedAtEntity(player, 5));
if (result != SpellCastResult.NONE) { if (result != CastResult.NONE) {
if (result == SpellCastResult.PLACE && !player.isCreative()) { if (result == CastResult.PLACE && !player.isCreative()) {
stack.decrement(1); stack.decrement(1);
} }

View file

@ -3,7 +3,7 @@ package com.minelittlepony.unicopia.item;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.minelittlepony.unicopia.SpeciesList; import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.item.consumables.ItemEdible; import com.minelittlepony.unicopia.item.consumables.EdibleItem;
import com.minelittlepony.unicopia.item.consumables.Toxicity; import com.minelittlepony.unicopia.item.consumables.Toxicity;
import com.minelittlepony.util.collection.ReversableStateMapList; import com.minelittlepony.util.collection.ReversableStateMapList;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -17,7 +17,7 @@ import net.minecraft.sound.SoundEvents;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
public class MossItem extends ItemEdible { public class MossItem extends EdibleItem {
public static final ReversableStateMapList AFFECTED = new ReversableStateMapList(); public static final ReversableStateMapList AFFECTED = new ReversableStateMapList();

View file

@ -1,8 +1,10 @@
package com.minelittlepony.unicopia.item; package com.minelittlepony.unicopia.item;
import com.minelittlepony.unicopia.ducks.IItemEntity;
import net.fabricmc.fabric.api.registry.FuelRegistry; import net.fabricmc.fabric.api.registry.FuelRegistry;
import net.minecraft.entity.ItemEntity;
import net.minecraft.item.FoodComponent; import net.minecraft.item.FoodComponent;
import net.minecraft.util.ActionResult;
public class RottenAppleItem extends AppleItem { public class RottenAppleItem extends AppleItem {
@ -12,7 +14,7 @@ public class RottenAppleItem extends AppleItem {
} }
@Override @Override
public boolean onEntityItemUpdate(ItemEntity item) { public ActionResult onGroundTick(IItemEntity item) {
return false; return ActionResult.PASS;
} }
} }

View file

@ -10,7 +10,6 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.FoodComponent;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
@ -20,8 +19,8 @@ import net.minecraft.world.World;
public class RottenTomatoItem extends TomatoItem implements ITossableItem { public class RottenTomatoItem extends TomatoItem implements ITossableItem {
public RottenTomatoItem(FoodComponent components) { public RottenTomatoItem(int hunger, float saturation) {
super(components); super(hunger, saturation);
setDispenseable(); setDispenseable();
} }

View file

@ -2,71 +2,66 @@ package com.minelittlepony.unicopia.item;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.minelittlepony.unicopia.entity.EntitySpear; import com.minelittlepony.unicopia.entity.SpearEntity;
import com.minelittlepony.unicopia.magic.ICaster; import com.minelittlepony.unicopia.magic.ICaster;
import com.minelittlepony.unicopia.projectile.IAdvancedProjectile; import com.minelittlepony.unicopia.projectile.IAdvancedProjectile;
import com.minelittlepony.unicopia.projectile.ITossableItem; import com.minelittlepony.unicopia.projectile.ITossableItem;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.UseAction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Position; import net.minecraft.util.math.Position;
import net.minecraft.world.World; import net.minecraft.world.World;
public class ItemSpear extends Item implements ITossableItem { public class SpearItem extends Item implements ITossableItem {
public ItemSpear(String domain, String name) { public SpearItem(Settings settings) {
setFull3D(); super(settings);
setTranslationKey(name);
setRegistryName(domain, name);
setMaxStackSize(1);
setMaxDamage(500);
} }
@Override @Override
public EnumAction getItemUseAction(ItemStack stack) { public UseAction getUseAction(ItemStack stack) {
return EnumAction.BOW; return UseAction.BOW;
} }
@Override @Override
public boolean isFull3D() { public int getMaxUseTime(ItemStack stack) {
return true;
}
@Override
public int getMaxItemUseDuration(ItemStack stack) {
return 440; return 440;
} }
@Override @Override
public TypedActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, EnumHand hand) { public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
if (!world.isClient) { if (!world.isClient) {
ItemStack itemstack = player.getStackInHand(hand); ItemStack itemstack = player.getStackInHand(hand);
if (canBeThrown(itemstack)) { if (canBeThrown(itemstack)) {
player.setActiveHand(hand); player.swingHand(hand);
return new TypedActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack); return new TypedActionResult<>(ActionResult.SUCCESS, itemstack);
} }
} }
return super.onItemRightClick(world, player, hand); return super.use(world, player, hand);
} }
@Override @Override
public void onPlayerStoppedUsing(ItemStack itemstack, World world, LivingEntity entity, int timeLeft) { public void onStoppedUsing(ItemStack itemstack, World world, LivingEntity entity, int timeLeft) {
if (entity instanceof PlayerEntity) { if (entity instanceof PlayerEntity) {
int i = getMaxItemUseDuration(itemstack) - timeLeft; int i = getMaxUseTime(itemstack) - timeLeft;
if (i > 10) { if (i > 10) {
if (canBeThrown(itemstack)) { if (canBeThrown(itemstack)) {
itemstack.damageItem(1, entity); itemstack.damage(1, entity, p -> p.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND));
toss(world, itemstack, (PlayerEntity)entity); toss(world, itemstack, (PlayerEntity)entity);
} }
} }
@ -90,7 +85,7 @@ public class ItemSpear extends Item implements ITossableItem {
@Nullable @Nullable
@Override @Override
public IAdvancedProjectile createProjectile(World world, PlayerEntity player) { public IAdvancedProjectile createProjectile(World world, PlayerEntity player) {
return new EntitySpear(world, player); return new SpearEntity(world, player);
} }
@Nullable @Nullable

View file

@ -0,0 +1,99 @@
package com.minelittlepony.unicopia.item;
import java.util.List;
import java.util.UUID;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.minelittlepony.unicopia.EquinePredicates;
import net.minecraft.block.Blocks;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SwordItem;
import net.minecraft.item.ToolMaterials;
import net.minecraft.particle.BlockStateParticleEffect;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Hand;
import net.minecraft.util.UseAction;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
public class StaffItem extends SwordItem {
protected static final UUID ATTACK_REACH_MODIFIER = UUID.fromString("FA235E1C-4280-A865-B01B-CBAE9985ACA3");
public StaffItem(Settings settings) {
super(ToolMaterials.WOOD, 2, 4, settings);
}
@Override
public boolean useOnEntity(ItemStack stack, PlayerEntity player, LivingEntity target, Hand hand) {
World w = player.getEntityWorld();
EntityDimensions dims = target.getDimensions(target.getPose());
for (int i = 0; i < 130; i++) {
w.addParticle(new BlockStateParticleEffect(ParticleTypes.BLOCK, Blocks.OAK_LOG.getDefaultState()),
target.x + (target.world.random.nextFloat() - 0.5F) * (dims.width + 1),
(target.y + dims.height / 2) + (target.world.random.nextFloat() - 0.5F) * dims.height,
target.z + (target.world.random.nextFloat() - 0.5F) * (dims.width + 1),
0, 0, 0
);
}
return false;
}
@Override
public void appendTooltip(ItemStack stack, World world, List<Text> tooltip, TooltipContext context) {
tooltip.add(new TranslatableText(getTranslationKey(stack) + ".tagline"));
}
@Override
public boolean postHit(ItemStack stack, LivingEntity entity, LivingEntity attacker) {
super.postHit(stack, entity, attacker);
if (EquinePredicates.MAGI.test(entity)) {
return castContainedEffect(stack, entity, attacker);
}
return false;
}
protected boolean castContainedEffect(ItemStack stack, LivingEntity target, LivingEntity attacker) {
target.getEntityWorld().playSound(null, target.getBlockPos(), SoundEvents.ENTITY_PLAYER_ATTACK_CRIT, attacker.getSoundCategory(), 1, 1);
target.takeKnockback(attacker, 2,
MathHelper.sin(attacker.yaw * 0.017453292F),
-MathHelper.cos(attacker.yaw * 0.017453292F)
);
return true;
}
@Override
public UseAction getUseAction(ItemStack stack) {
return UseAction.BOW;
}
@Override
public Multimap<String, EntityAttributeModifier> getModifiers(EquipmentSlot slot) {
Multimap<String, EntityAttributeModifier> multimap = HashMultimap.create();
if (slot == EquipmentSlot.MAINHAND) {
multimap.put(EntityAttributes.ATTACK_DAMAGE.getId(), new EntityAttributeModifier(ATTACK_DAMAGE_MODIFIER_UUID, "Weapon modifier", getAttackDamage(), EntityAttributeModifier.Operation.ADDITION));
//multimap.put(PlayerEntity.REACH_DISTANCE.getId(), new EntityAttributeModifier(ATTACK_REACH_MODIFIER, "Weapon modifier", 3, EntityAttributeModifier.Operation.ADDITION));
}
return multimap;
}
}

Some files were not shown because too many files have changed in this diff Show more