use of icbm.classic.api.reg.IExplosiveData in project ICBM-Classic by BuiltBrokenModding.
the class BlockExplosive method getStateForPlacement.
@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
ItemStack stack = placer.getHeldItem(hand);
IBlockState state = getDefaultState().withProperty(ROTATION_PROP, facing);
IExplosiveData prop = ICBMClassicAPI.EXPLOSIVE_REGISTRY.getExplosiveData(stack.getItemDamage());
if (prop != null) {
return state.withProperty(EX_PROP, prop);
} else {
// if the explosives id doesnt exist, then fallback to the one with the id 0
prop = ICBMClassicAPI.EXPLOSIVE_REGISTRY.getExplosiveData(0);
ICBMClassic.logger().log(Level.ERROR, "Unable to get explosives kind, choosing " + prop.getRegistryName().toString() + " as a fallback.");
stack.setItemDamage(0);
return state.withProperty(EX_PROP, prop);
}
}
use of icbm.classic.api.reg.IExplosiveData in project ICBM-Classic by BuiltBrokenModding.
the class ClientReg method registerCartRenders.
protected static void registerCartRenders() {
for (// TODO run loop once for all 4 content types
IExplosiveData data : // TODO run loop once for all 4 content types
ICBMClassicAPI.EX_MINECART_REGISTRY.getExplosives()) {
final String resourcePath = data.getRegistryName().getNamespace() + ":bombcarts/" + data.getRegistryName().getPath();
cartModelMap.put(data, new ModelResourceLocation(resourcePath, "inventory"));
}
ModelLoader.registerItemVariants(ItemReg.itemBombCart, cartModelMap.values().stream().map(model -> new ResourceLocation(model.getNamespace() + ":" + model.getPath())).toArray(ResourceLocation[]::new));
ModelLoader.setCustomMeshDefinition(ItemReg.itemBombCart, new ItemModelMapperExplosive(cartModelMap, cartModelMap.get(ICBMExplosives.CONDENSED)));
}
use of icbm.classic.api.reg.IExplosiveData in project ICBM-Classic by BuiltBrokenModding.
the class ClientReg method registerExBlockRenders.
protected static void registerExBlockRenders() {
for (// TODO run loop once for all 4 content types
IExplosiveData data : // TODO run loop once for all 4 content types
ICBMClassicAPI.EX_BLOCK_REGISTRY.getExplosives()) {
// Add block state
final HashMap<EnumFacing, ModelResourceLocation> facingModelMap = new HashMap<>();
final String resourcePath = data.getRegistryName().getNamespace() + ":explosives/" + data.getRegistryName().getPath();
for (EnumFacing facing : EnumFacing.VALUES) {
facingModelMap.put(facing, new ModelResourceLocation(resourcePath, "explosive=" + data.getRegistryName().toString().replace(":", "_") + ",rotation=" + facing));
}
blockModelMap.put(data, facingModelMap);
// Add item state
// IBlockState state = BlockReg.blockExplosive.getDefaultState().withProperty(BlockICBM.ROTATION_PROP, EnumFacing.UP);
// String properties_string = getPropertyString(state.getProperties());
itemBlockModelMap.put(data, new ModelResourceLocation(resourcePath, "inventory"));
}
// Block state mapper
ModelLoader.setCustomStateMapper(BlockReg.blockExplosive, new BlockModelMapperExplosive(blockModelMap, blockModelMap.get(ICBMExplosives.CONDENSED).get(EnumFacing.UP)));
// Item state mapper
ModelLoader.setCustomMeshDefinition(Item.getItemFromBlock(BlockReg.blockExplosive), new ItemModelMapperExplosive(itemBlockModelMap, itemBlockModelMap.get(ICBMExplosives.CONDENSED)));
ModelBakery.registerItemVariants(Item.getItemFromBlock(BlockReg.blockExplosive), itemBlockModelMap.values().stream().map(mrl -> new ResourceLocation(mrl.getNamespace(), mrl.getPath())).collect(Collectors.toList()).toArray(new ResourceLocation[itemBlockModelMap.values().size()]));
}
use of icbm.classic.api.reg.IExplosiveData in project ICBM-Classic by BuiltBrokenModding.
the class CommandBlastSpread method doCommand.
private void doCommand(@Nonnull ICommandSender sender, @Nonnull String[] args) throws CommandException {
final int count = CommandBase.parseInt(args[0], 1);
final int distance = CommandBase.parseInt(args[1], 1);
// Get explosive data from user
final IExplosiveData explosiveData = CommandBlastTrigger.getExplosive(args[2]);
// Get world position
final World world = CommandUtils.getWorld(sender, args[3], sender.getEntityWorld());
final double xInput = CommandUtils.getNumber(sender, args[4], sender.getPosition().getX() + 0.5);
final double yInput = CommandUtils.getNumber(sender, args[5], sender.getPosition().getY() + 0.5);
final double zInput = CommandUtils.getNumber(sender, args[6], sender.getPosition().getZ() + 0.5);
// Get scale from user
// TODO turn into helper method
final float scale = Float.parseFloat(args[7]);
if (scale <= 0) {
throw new SyntaxErrorException(CommandBlastTrigger.TRANSLATION_ERROR_SCALE_ZERO);
}
final int expectedSpawnCount = (int) Math.floor(Math.pow((count * 2) + 1, 2));
sender.sendMessage(new TextComponentTranslation(TRANSLATION_SPREAD_START, explosiveData.getRegistryName(), scale, world.provider.getDimension(), world.getWorldType().getName(), xInput, yInput, zInput, count, distance, expectedSpawnCount));
// Generate blasts in a grid
for (int xi = -count; xi <= count; xi++) {
for (int zi = -count; zi <= count; zi++) {
// calc position
final double x = xInput + xi * distance;
final double z = zInput + zi * distance;
// Trigger blast
final BlastState result = ExplosiveHandler.createExplosion(null, world, x, yInput, z, explosiveData.getRegistryID(), scale, null);
if (result != BlastState.TRIGGERED && result != BlastState.THREADING) {
// Send translated message to user
sender.sendMessage(new TextComponentTranslation(CommandBlastTrigger.getTranslationKey(result), explosiveData.getRegistryName(), scale, world.provider.getDimension(), world.getWorldType().getName(), x, yInput, z));
}
}
}
}
use of icbm.classic.api.reg.IExplosiveData in project ICBM-Classic by BuiltBrokenModding.
the class ExplosiveContentRegistry method lockRegistry.
@Override
public void lockRegistry() {
if (!locked) {
locked = true;
// Turn into immutable
nameCache = ImmutableSet.copyOf(nameCache);
// Generate reference map
final HashMap<ResourceLocation, IExplosiveData> map = new HashMap();
for (ResourceLocation name : nameCache) {
final IExplosiveData data = ICBMClassicAPI.EXPLOSIVE_REGISTRY.getExplosiveData(name);
if (data != null) {
map.put(name, data);
} else {
throw new RuntimeException(this + ": Failed to locate explosive by name " + name);
}
}
mapCache = ImmutableMap.copyOf(map);
// Map ids to cache
idCache = map.values().stream().map(entry -> entry.getRegistryID()).collect(ImmutableSet.toImmutableSet());
dataCache = map.values().stream().collect(ImmutableSet.toImmutableSet());
} else
throw new RuntimeException(this + ": Registry was locked twice!");
}
Aggregations