Remembered after the fact to add the new stuff too.
This commit is contained in:
parent
e3b3d69d1d
commit
ee71072969
8 changed files with 580 additions and 0 deletions
|
@ -0,0 +1,41 @@
|
|||
package WayofTime.bloodmagic.meteor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class MeteorComponent
|
||||
{
|
||||
public int weight;
|
||||
public String oreName;
|
||||
|
||||
public IBlockState getStateFromOre()
|
||||
{
|
||||
List<ItemStack> list = OreDictionary.getOres(oreName);
|
||||
if (list != null && !list.isEmpty())
|
||||
{
|
||||
for (ItemStack stack : list)
|
||||
{
|
||||
if (stack != null && stack.getItem() instanceof ItemBlock)
|
||||
{
|
||||
Block block = ((ItemBlock) stack.getItem()).getBlock();
|
||||
IBlockState state = block.getStateFromMeta(stack.getItemDamage());
|
||||
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
74
src/main/java/WayofTime/bloodmagic/meteor/MeteorHolder.java
Normal file
74
src/main/java/WayofTime/bloodmagic/meteor/MeteorHolder.java
Normal file
|
@ -0,0 +1,74 @@
|
|||
package WayofTime.bloodmagic.meteor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import WayofTime.bloodmagic.util.Utils;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class MeteorHolder
|
||||
{
|
||||
public static Random rand = new Random();
|
||||
public List<MeteorComponent> components = new ArrayList<MeteorComponent>();
|
||||
|
||||
public float explosionStrength;
|
||||
public int radius;
|
||||
|
||||
public int maxWeight = 1000;
|
||||
|
||||
public void generateMeteor(World world, BlockPos pos, IBlockState fillerBlock)
|
||||
{
|
||||
world.newExplosion(null, pos.getX(), pos.getY(), pos.getZ(), explosionStrength, true, true);
|
||||
|
||||
for (int i = -radius; i <= radius; i++)
|
||||
{
|
||||
for (int j = -radius; j <= radius; j++)
|
||||
{
|
||||
for (int k = -radius; k <= radius; k++)
|
||||
{
|
||||
if (i * i + j * j + k * k > (radius + 0.5) * (radius + 0.5))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
BlockPos newPos = pos.add(i, j, k);
|
||||
IBlockState state = world.getBlockState(newPos);
|
||||
|
||||
if (world.isAirBlock(newPos) || Utils.isBlockLiquid(state))
|
||||
{
|
||||
IBlockState placedState = getRandomOreFromComponents(fillerBlock);
|
||||
world.setBlockState(newPos, placedState);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IBlockState getRandomOreFromComponents(IBlockState fillerBlock)
|
||||
{
|
||||
int goal = rand.nextInt(maxWeight);
|
||||
|
||||
for (MeteorComponent component : components)
|
||||
{
|
||||
goal -= component.getWeight();
|
||||
if (goal < 0)
|
||||
{
|
||||
IBlockState state = component.getStateFromOre();
|
||||
if (state != null)
|
||||
{
|
||||
return state;
|
||||
} else
|
||||
{
|
||||
return fillerBlock;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fillerBlock;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package WayofTime.bloodmagic.meteor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import WayofTime.bloodmagic.api.ItemStackWrapper;
|
||||
|
||||
public class MeteorRegistry
|
||||
{
|
||||
public static Map<ItemStackWrapper, MeteorHolder> meteorMap = new HashMap<ItemStackWrapper, MeteorHolder>();
|
||||
|
||||
public static void registerMeteor(ItemStack stack, MeteorHolder holder)
|
||||
{
|
||||
ItemStackWrapper wrapper = ItemStackWrapper.getHolder(stack);
|
||||
if (wrapper != null)
|
||||
{
|
||||
meteorMap.put(wrapper, holder);
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerMeteor(ItemStack stack, List<MeteorComponent> componentList, float explosionStrength, int radius, int maxWeight)
|
||||
{
|
||||
MeteorHolder holder = new MeteorHolder(componentList, explosionStrength, radius, maxWeight);
|
||||
|
||||
registerMeteor(stack, holder);
|
||||
}
|
||||
|
||||
public static boolean hasMeteorForItem(ItemStack stack)
|
||||
{
|
||||
ItemStackWrapper wrapper = ItemStackWrapper.getHolder(stack);
|
||||
return wrapper != null && meteorMap.containsKey(wrapper);
|
||||
}
|
||||
|
||||
public static MeteorHolder getMeteorForItem(ItemStack stack)
|
||||
{
|
||||
ItemStackWrapper wrapper = ItemStackWrapper.getHolder(stack);
|
||||
return wrapper != null ? meteorMap.get(wrapper) : null;
|
||||
}
|
||||
|
||||
public static void generateMeteorForItem(ItemStack stack, World world, BlockPos pos, IBlockState fillerBlock)
|
||||
{
|
||||
MeteorHolder holder = getMeteorForItem(stack);
|
||||
if (holder != null)
|
||||
{
|
||||
holder.generateMeteor(world, pos, fillerBlock);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue