Started adding a gem-based torch

This commit is contained in:
Sollace 2019-02-07 19:18:51 +02:00
parent 80641176d3
commit a094d68d5e
10 changed files with 220 additions and 9 deletions

View file

@ -2,6 +2,7 @@ package com.minelittlepony.unicopia;
import com.minelittlepony.unicopia.block.BlockAlfalfa;
import com.minelittlepony.unicopia.block.BlockFruitLeaves;
import com.minelittlepony.unicopia.block.BlockGlowingGem;
import com.minelittlepony.unicopia.block.BlockCloud;
import com.minelittlepony.unicopia.block.BlockCloudAnvil;
import com.minelittlepony.unicopia.block.BlockCloudBanister;
@ -40,6 +41,8 @@ public class UBlocks {
public static final BlockCloudDoor mist_door = new BlockCloudDoor(UMaterials.cloud, Unicopia.MODID, "mist_door");
public static final BlockGlowingGem enchanted_torch = new BlockGlowingGem(Unicopia.MODID, "enchanted_torch");
public static final BlockCloudAnvil anvil = new BlockCloudAnvil(Unicopia.MODID, "anvil");
public static final BlockCloudFence cloud_fence = new BlockCloudFence(Unicopia.MODID, "cloud_fence");
@ -67,6 +70,7 @@ public class UBlocks {
sugar_block,
alfalfa,
tomato_plant,
enchanted_torch,
apple_tree, apple_leaves);
}

View file

@ -29,6 +29,7 @@ import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemDoor;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemSeedFood;
@ -113,6 +114,8 @@ public class UItems {
.setCreativeTab(CreativeTabs.MATERIALS);
public static final ItemStick stick = new ItemStick();
public static final Item enchanted_torch = new ItemBlock(UBlocks.enchanted_torch)
.setRegistryName(Unicopia.MODID, "enchanted_torch");
public static final Item alfalfa_leaves = new ItemFood(1, 3, false)
.setTranslationKey("alfalfa_leaves")
@ -202,7 +205,7 @@ public class UItems {
cloud_stairs, cloud_slab, cloud_fence, cloud_banister,
cloud_farmland, mist_door, anvil,
bag_of_holding, spell, curse, spellbook, mug,
bag_of_holding, spell, curse, spellbook, mug, enchanted_torch,
alfalfa_seeds, alfalfa_leaves,
cereal, sugar_cereal, sugar_block,
@ -230,7 +233,7 @@ public class UItems {
cloud_spawner, cloud_matter, cloud_stairs, cloud_fence, cloud_banister,
cloud_farmland, mist_door, anvil,
bag_of_holding, spell, curse, spellbook, mug,
bag_of_holding, spell, curse, spellbook, mug, enchanted_torch,
alfalfa_seeds, alfalfa_leaves,
cereal, sugar_cereal, sugar_block,

View file

@ -0,0 +1,105 @@
package com.minelittlepony.unicopia.block;
import java.util.Random;
import com.minelittlepony.unicopia.CloudType;
import com.minelittlepony.unicopia.UParticles;
import com.minelittlepony.unicopia.particle.Particles;
import net.minecraft.block.BlockTorch;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockGlowingGem extends BlockTorch implements ICloudBlock {
private static final double A = 5/16D;
private static final double B = 6/16D;
private static final double C = 10/16D;
// tiltedOffWall
private static final double F = 10/16D;
// tiltedMinY
private static final double E = 3/16D;
protected static final AxisAlignedBB STANDING_AABB = new AxisAlignedBB(
7/16D, 0, 7/16D,
9/16D, 1, 9/16D
);
protected static final AxisAlignedBB TORCH_NORTH_AABB = new AxisAlignedBB(
B, E, F,
C, 1, 1
);
protected static final AxisAlignedBB TORCH_SOUTH_AABB = new AxisAlignedBB(
B, E, 0,
C, 1, A
);
protected static final AxisAlignedBB TORCH_WEST_AABB = new AxisAlignedBB(
F, E, B,
1, 1, C
);
protected static final AxisAlignedBB TORCH_EAST_AABB = new AxisAlignedBB(
0, E, B,
A, 1, C
);
public BlockGlowingGem(String domain, String name) {
super();
setTranslationKey(name);
setRegistryName(domain, name);
setHardness(0);
setLightLevel(1);
setSoundType(SoundType.GLASS);
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
switch (state.getValue(FACING)) {
case EAST: return TORCH_EAST_AABB;
case WEST: return TORCH_WEST_AABB;
case SOUTH: return TORCH_SOUTH_AABB;
case NORTH: return TORCH_NORTH_AABB;
default: return STANDING_AABB;
}
}
@Override
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand) {
EnumFacing facing = state.getValue(FACING);
double x = pos.getX() + 0.5;
double y = pos.getY() + 0.7;
double z = pos.getZ() + 0.5;
double drop = 0.22D;
double variance = 0.27D;
if (facing.getAxis().isHorizontal()) {
facing = facing.getOpposite();
x += variance * facing.getXOffset();
y += drop;
z += variance * facing.getZOffset();
}
for (int i = 0; i < 3; i++) {
Particles.instance().spawnParticle(UParticles.UNICORN_MAGIC, false,
x - 0.3, y, z - 0.3,
rand.nextFloat(), rand.nextFloat(), rand.nextFloat());
}
}
@Override
public CloudType getCloudMaterialType(IBlockState blockState) {
return CloudType.ENCHANTED;
}
}

View file

@ -52,6 +52,15 @@ public interface ICloudBlock {
}
if (isPlacementExcempt(block)) {
if (block instanceof ICloudBlock) {
CloudType other = ((ICloudBlock)block).getCloudMaterialType(block.getDefaultState());
if (other.canInteract(player)) {
return false;
}
}
if (Predicates.INTERACT_WITH_CLOUDS.apply(player)) {
return type == CloudType.NORMAL;
}

View file

@ -68,9 +68,13 @@ public class ParticleUnicornMagic extends Particle {
prevPosZ = posZ;
float var1 = (float)particleAge / (float)particleMaxAge;
var1 = 1 + var1 - var1 * var1 * 2;
posX = portalPosX + motionX * var1;
posY = portalPosY + motionY;
posZ = portalPosZ + motionZ * var1;
if (particleAge++ >= particleMaxAge) setExpired();
if (particleAge++ >= particleMaxAge) {
setExpired();
}
}
}

View file

@ -0,0 +1,49 @@
package com.minelittlepony.unicopia.spell;
import java.util.function.Supplier;
import com.minelittlepony.unicopia.UParticles;
public class GenericSpell extends AbstractSpell {
private final String name;
private final int tint;
private final SpellAffinity affinity;
static Supplier<IMagicEffect> factory(String name, int tint, SpellAffinity affinity) {
return () -> new GenericSpell(name, tint, affinity);
}
public GenericSpell(String name, int tint, SpellAffinity affinity) {
this.name = name;
this.tint = tint;
this.affinity = affinity;
}
@Override
public String getName() {
return name;
}
@Override
public int getTint() {
return tint;
}
@Override
public boolean update(ICaster<?> source) {
return true;
}
@Override
public void render(ICaster<?> source) {
source.spawnParticles(UParticles.UNICORN_MAGIC, 1);
}
@Override
public SpellAffinity getAffinity() {
return affinity;
}
}

View file

@ -5,7 +5,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.function.Supplier;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -42,6 +42,7 @@ public class SpellRegistry {
registerSpell(SpellAwkward::new);
registerSpell(SpellInferno::new);
registerSpell(SpellDrake::new);
registerSpell(GenericSpell.factory("light", 0xf0ff0f, SpellAffinity.GOOD));
}
@Nullable
@ -99,7 +100,7 @@ public class SpellRegistry {
return getSpellFromName(getKeyFromStack(stack));
}
public <T extends IMagicEffect> void registerSpell(Callable<T> factory) {
public <T extends IMagicEffect> void registerSpell(Supplier<T> factory) {
try {
new Entry<T>(factory);
} catch (Exception e) {
@ -157,7 +158,7 @@ public class SpellRegistry {
@Immutable
class Entry<T extends IMagicEffect> {
final Callable<T> factory;
final Supplier<T> factory;
final int color;
@ -166,8 +167,8 @@ public class SpellRegistry {
final SpellAffinity affinity;
Entry(Callable<T> factory) throws Exception {
T inst = factory.call();
Entry(Supplier<T> factory) throws Exception {
T inst = factory.get();
this.factory = factory;
this.color = inst.getTint();
@ -202,7 +203,7 @@ public class SpellRegistry {
T create() {
try {
return factory.call();
return factory.get();
} catch (Exception e) {
e.printStackTrace();
}

View file

@ -0,0 +1,9 @@
{
"variants": {
"facing=up": { "model": "unicopia:enchanted_torch" },
"facing=east": { "model": "unicopia:enchanted_torch_wall" },
"facing=south": { "model": "unicopia:enchanted_torch_wall", "y": 90 },
"facing=west": { "model": "unicopia:enchanted_torch_wall", "y": 180 },
"facing=north": { "model": "unicopia:enchanted_torch_wall", "y": 270 }
}
}

View file

@ -0,0 +1,21 @@
{
"ambientocclusion": false,
"textures": {
"torch": "blocks/torch_on",
"particle": "blocks/torch_on"
},
"elements": [
{ "from": [ 7, 0, 7 ],
"to": [ 9, 16, 9 ],
"shade": false,
"faces": {
"down": { "uv": [ 7, 13, 9, 15 ], "texture": "#torch" },
"up": { "uv": [ 7, 6, 9, 8 ], "texture": "#torch" },
"north": { "uv": [ 7, 0, 9, 16 ], "texture": "#torch" },
"south": { "uv": [ 7, 0, 9, 16 ], "texture": "#torch" },
"west": { "uv": [ 7, 0, 9, 16 ], "texture": "#torch" },
"east": { "uv": [ 7, 0, 9, 16 ], "texture": "#torch" }
}
}
]
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "blocks/torch_on"
}
}