Skip to content

Commit

Permalink
Generate blocks in Common
Browse files Browse the repository at this point in the history
  • Loading branch information
Griefed committed Nov 6, 2023
1 parent a5d7416 commit 698b5db
Show file tree
Hide file tree
Showing 36 changed files with 793 additions and 364 deletions.
142 changes: 21 additions & 121 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,121 +1,21 @@
Creative Commons Legal Code

CC0 1.0 Universal

CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
HEREUNDER.

Statement of Purpose

The laws of most jurisdictions throughout the world automatically confer
exclusive Copyright and Related Rights (defined below) upon the creator
and subsequent owner(s) (each and all, an "owner") of an original work of
authorship and/or a database (each, a "Work").

Certain owners wish to permanently relinquish those rights to a Work for
the purpose of contributing to a commons of creative, cultural and
scientific works ("Commons") that the public can reliably and without fear
of later claims of infringement build upon, modify, incorporate in other
works, reuse and redistribute as freely as possible in any form whatsoever
and for any purposes, including without limitation commercial purposes.
These owners may contribute to the Commons to promote the ideal of a free
culture and the further production of creative, cultural and scientific
works, or to gain reputation or greater distribution for their Work in
part through the use and efforts of others.

For these and/or other purposes and motivations, and without any
expectation of additional consideration or compensation, the person
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
is an owner of Copyright and Related Rights in the Work, voluntarily
elects to apply CC0 to the Work and publicly distribute the Work under its
terms, with knowledge of his or her Copyright and Related Rights in the
Work and the meaning and intended legal effect of CC0 on those rights.

1. Copyright and Related Rights. A Work made available under CC0 may be
protected by copyright and related or neighboring rights ("Copyright and
Related Rights"). Copyright and Related Rights include, but are not
limited to, the following:

i. the right to reproduce, adapt, distribute, perform, display,
communicate, and translate a Work;
ii. moral rights retained by the original author(s) and/or performer(s);
iii. publicity and privacy rights pertaining to a person's image or
likeness depicted in a Work;
iv. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(a), below;
v. rights protecting the extraction, dissemination, use and reuse of data
in a Work;
vi. database rights (such as those arising under Directive 96/9/EC of the
European Parliament and of the Council of 11 March 1996 on the legal
protection of databases, and under any national implementation
thereof, including any amended or successor version of such
directive); and
vii. other similar, equivalent or corresponding rights throughout the
world based on applicable law or treaty, and any national
implementations thereof.

2. Waiver. To the greatest extent permitted by, but not in contravention
of, applicable law, Affirmer hereby overtly, fully, permanently,
irrevocably and unconditionally waives, abandons, and surrenders all of
Affirmer's Copyright and Related Rights and associated claims and causes
of action, whether now known or unknown (including existing as well as
future claims and causes of action), in the Work (i) in all territories
worldwide, (ii) for the maximum duration provided by applicable law or
treaty (including future time extensions), (iii) in any current or future
medium and for any number of copies, and (iv) for any purpose whatsoever,
including without limitation commercial, advertising or promotional
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
member of the public at large and to the detriment of Affirmer's heirs and
successors, fully intending that such Waiver shall not be subject to
revocation, rescission, cancellation, termination, or any other legal or
equitable action to disrupt the quiet enjoyment of the Work by the public
as contemplated by Affirmer's express Statement of Purpose.

3. Public License Fallback. Should any part of the Waiver for any reason
be judged legally invalid or ineffective under applicable law, then the
Waiver shall be preserved to the maximum extent permitted taking into
account Affirmer's express Statement of Purpose. In addition, to the
extent the Waiver is so judged Affirmer hereby grants to each affected
person a royalty-free, non transferable, non sublicensable, non exclusive,
irrevocable and unconditional license to exercise Affirmer's Copyright and
Related Rights in the Work (i) in all territories worldwide, (ii) for the
maximum duration provided by applicable law or treaty (including future
time extensions), (iii) in any current or future medium and for any number
of copies, and (iv) for any purpose whatsoever, including without
limitation commercial, advertising or promotional purposes (the
"License"). The License shall be deemed effective as of the date CC0 was
applied by Affirmer to the Work. Should any part of the License for any
reason be judged legally invalid or ineffective under applicable law, such
partial invalidity or ineffectiveness shall not invalidate the remainder
of the License, and in such case Affirmer hereby affirms that he or she
will not (i) exercise any of his or her remaining Copyright and Related
Rights in the Work or (ii) assert any associated claims and causes of
action with respect to the Work, in either case contrary to Affirmer's
express Statement of Purpose.

4. Limitations and Disclaimers.

a. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.
b. Affirmer offers the Work as-is and makes no representations or
warranties of any kind concerning the Work, express, implied,
statutory or otherwise, including without limitation warranties of
title, merchantability, fitness for a particular purpose, non
infringement, or the absence of latent or other defects, accuracy, or
the present or absence of errors, whether or not discoverable, all to
the greatest extent permissible under applicable law.
c. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without
limitation any person's Copyright and Related Rights in the Work.
Further, Affirmer disclaims responsibility for obtaining any necessary
consents, permissions or other rights required for any use of the
Work.
d. Affirmer understands and acknowledges that Creative Commons is not a
party to this document and has no duty or obligation with respect to
this CC0 or use of the Work.
MIT License

Copyright (c) 2023 Griefed

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
[![](http://cf.way2muchnoise.eu/versions/415747.svg)](https://www.curseforge.com/minecraft/mc-mods/crumbs)
-->

Assortment of blocks I want to use.

## What does this mod do?

This mod adds an assortment of blocks I would like to use in Minecraft. Mainly blocks inspired by the aesthetic of Half Life 2's Citadel,
Expand All @@ -33,6 +31,6 @@ This guide will show how to import the MultiLoader Template into IntelliJ IDEA.
7. Assuming you were able to run the game in step 7 your workspace should now be set up.

## Development Guide
When using this template the majority of your mod is developed in the Common project. The Common project is compiled against the vanilla game and is used to hold code that is shared between the different loader-specific versions of your mod. The Common project has no knowledge or access to ModLoader specific code, apis, or concepts. Code that requires something from a specific loader must be done through the project that is specific to that loader, such as the Forge or Fabric project.

When using this template the majority of your mod is developed in the Common project. The Common project is compiled against the vanilla game and is used to hold code that is shared between the different loader-specific versions of your mod. The Common project has no knowledge or access to ModLoader specific code, apis, or concepts. Code that requires something from a specific loader must be done through the project that is specific to that loader, such as the Forge or Fabric project.
Loader specific projects such as the Forge and Fabric project are used to load the Common project into the game. These projects also define code that is specific to that loader. Loader specific projects can access all of the code in the Common project. It is important to remember that the Common project can not access code from loader specific projects.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public void apply(Project project) {
String modName = gradleProperties.getProperty("mod_name");
BlockDefinitionParser parser = new BlockDefinitionParser(project, objectMapper);

CommonGeneration common = new CommonGeneration(project.findProject("common"), modName, parser, objectMapper);
FabricGeneration fabric = new FabricGeneration(project.findProject("fabric"), modName, parser, objectMapper);
ForgeGeneration forge = new ForgeGeneration(project.findProject("forge"), modName, parser, objectMapper);
CommonGeneration common = new CommonGeneration(project.findProject("Common"), modName, parser, objectMapper);
//FabricGeneration fabric = new FabricGeneration(project.findProject("fabric"), modName, parser, objectMapper);
//ForgeGeneration forge = new ForgeGeneration(project.findProject("forge"), modName, parser, objectMapper);

common.run();
fabric.run();
forge.run();
//fabric.run();
//forge.run();
} catch (IOException e) {
throw new RuntimeException("Error generating block and item code.", e);
}
Expand Down
115 changes: 114 additions & 1 deletion buildSrc/src/main/java/de/griefed/generation/CommonGeneration.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,132 @@
package de.griefed.generation;

import com.fasterxml.jackson.databind.ObjectMapper;
import de.griefed.generation.blocks.BlockDefinition;
import de.griefed.generation.blocks.BlockDefinitionParser;
import org.gradle.api.Project;

import java.io.IOException;

public class CommonGeneration extends ModloaderGeneration {
public class CommonGeneration extends ModloaderGeneration implements CodeGeneration {
protected CommonGeneration(Project project, String modName, BlockDefinitionParser parser, ObjectMapper objectMapper) {
super(project, modName, parser, objectMapper);
}

private final String modBlockClassTemplate = StringTemplates.COMMON_MODBLOCKS_CLASS
.replace("GROUP", getGroup());

private final String modItemsClassTemplate = StringTemplates.COMMON_ITEMS_CLASS
.replace("GROUP", getGroup());

private final String modloaderClassTemplate = StringTemplates.COMMON_MAIN_CLASS
.replace("GROUP", getGroup())
.replace("MODID", getId());

public void run() throws IOException {
createModBlockPackage();
createItemPackage();
createModBlocksClass();
createModItemsClass();
createModloaderClass();
updateTranslations();
createBlockFiles();
createItemFiles();
updateModBlocksClass();
updateModItemsClass();
updateModloaderMain();
}

@Override
public void createModBlocksClass() throws IOException {
if (!getModBlocksClass().exists() && getModBlocksClass().createNewFile()) {
System.out.println("ModBlock-class created: " + getModBlocksClass().getAbsolutePath());
writeToFile(getModBlocksClass(), modBlockClassTemplate);
}
}

@Override
public void createModItemsClass() throws IOException {
if (!getModItemsClass().exists() && getModItemsClass().createNewFile()) {
System.out.println("ModItems-class created: " + getModItemsClass().getAbsolutePath());
writeToFile(getModItemsClass(), modItemsClassTemplate);
}
}

@Override
public void createModloaderClass() throws IOException {
if (!getModloaderClass().exists() && getModloaderClass().createNewFile()) {
System.out.println("ModItems-class created: " + getModloaderClass().getAbsolutePath());
writeToFile(getModloaderClass(), modloaderClassTemplate);
}
}

//public static final RegistryObject<Block> SILVERBLOCK = BLOCKS.register("silverblock", () -> new Block(
// BlockBehaviour.Properties.of(Material.METAL).sound(SoundType.STONE).strength(12f, 10f).requiresCorrectToolForDrops()));
//public static final RegistryObject<Item> SILVERBLOCK_ITEM = ITEMS.register("silverblock", () -> new BlockItem(SILVERBLOCK.get(), itemBuilder()));
@Override
public void updateModBlocksClass() throws IOException {
String modBlocks = readFromFile(getModBlocksClass());
StringBuilder blocks = new StringBuilder();
StringBuilder registration;
for (BlockDefinition block : getBlockDefinitionParser().getBlocks()) {
registration = new StringBuilder();
//block
registration.append("\n\tpublic static final RegistryObject<Block> ").append(block.getId().toUpperCase()).append(" = BLOCKS.register(\"").append(block.getId()).append("_block\", () -> new Block(\n")
.append("\t\t\tBlockBehaviour.Properties.of(Material.").append(block.getMaterial()).append(").sound(SoundType.").append(block.getSoundType()).append(").strength(").append(block.getStrengthOne()).append("f, ").append(block.getStrengthTwo()).append("f)\n")
.append("\t\t\t\t\t").append(".lightLevel(state -> ").append(block.getLightLevel()).append(")").append(".explosionResistance(").append(block.getExplosionResistance()).append("f)\n\t\t\t\t\t");
if (block.isRequiresCorrectTool()) {
registration.append(".requiresCorrectToolForDrops()");
}
if (block.isInstabreak()) {
registration.append(".instabreak()");
}
registration.append("));\n");

//block item
registration.append("\n\tpublic static final RegistryObject<Item> ").append(block.getId().toUpperCase()).append("_ITEM = ITEMS.register(\"").append(block.getId()).append("\", () -> new BlockItem(").append(block.getId().toUpperCase()).append(".get(), itemBuilder()));\n");

blocks.append(registration);
}
modBlocks = CODE_REPLACE
.matcher(modBlocks)
.replaceAll("/*###GENERATED CODE - DO NOT EDIT - MANUALLY EDITED CODE WILL BE LOST###*/" +
blocks +
"\t/*###GENERATED CODE - DO NOT EDIT - MANUALLY EDITED CODE WILL BE LOST###*/");
writeToFile(getModBlocksClass(), modBlocks);
}


//public static final RegistryObject<Item> SILVERNUGGET = ITEMS.register("silvernugget", () -> new Item(itemBuilder().stacksTo(64).rarity(Rarity.COMMON)));
@Override
public void updateModItemsClass() throws IOException {
String modItems = readFromFile(getModItemsClass());
StringBuilder items = new StringBuilder();
StringBuilder registration;
/*for (ItemDefinition item : getItemDefinitionParser().getItems()) {
registration = new StringBuilder();
registration.append("\n\tpublic static final RegistryObject<Item> ").append(item.getId().toUpperCase()).append(" = ITEMS.register(\"").append(item.getId()).append("\",\n")
.append("\t\t\t() -> new Item(new Item.Properties()));");
registration.append("\n");
items.append(registration);
}*/
modItems = CODE_REPLACE
.matcher(modItems)
.replaceAll("/*###GENERATED CODE - DO NOT EDIT - MANUALLY EDITED CODE WILL BE LOST###*/\n\n" +
items +
"\t/*###GENERATED CODE - DO NOT EDIT - MANUALLY EDITED CODE WILL BE LOST###*/");
writeToFile(getModItemsClass(), modItems);
}

@Override
public void updateModloaderMain() throws IOException {
String modloaderMain = readFromFile(getModloaderClass());
modloaderMain = CODE_REPLACE
.matcher(modloaderMain)
.replaceAll("""
/*###GENERATED CODE - DO NOT EDIT - MANUALLY EDITED CODE WILL BE LOST###*/
\t\tGeneratedModBlocks.loadClass();
\t\tGeneratedModItems.loadClass();
\t\t/*###GENERATED CODE - DO NOT EDIT - MANUALLY EDITED CODE WILL BE LOST###*/""");
writeToFile(getModloaderClass(), modloaderMain);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ public FabricGeneration(Project project, String modName, BlockDefinitionParser p

@Override
public void run() throws IOException {
createModBlockPackage();
createItemPackage();
createModBlocksClass();
createModItemsClass();
createModloaderClass();
updateModBlocksClass();
updateModItemsClass();
updateModloaderMain();
// createModBlockPackage();
// createItemPackage();
// createModBlocksClass();
// createModItemsClass();
// createModloaderClass();
// updateModBlocksClass();
// updateModItemsClass();
// updateModloaderMain();
}

@Override
Expand Down Expand Up @@ -79,7 +79,7 @@ public void updateModBlocksClass() throws IOException {
for (BlockDefinition block : getBlockDefinitionParser().getBlocks()) {
registration = new StringBuilder();
registration.append("\n\tpublic static final Block ").append(block.getId().toUpperCase()).append("_BLOCK = registerBlock(\"").append(block.getId()).append("_block\",\n")
.append("\t\t\tnew Block(FabricBlockSettings.of(Material.").append(block.getMaterial()).append(").strength(").append(block.getStrength()).append("f).luminance(").append(block.getLightLevel()).append(")\n")
.append("\t\t\tnew Block(FabricBlockSettings.of(Material.").append(block.getMaterial()).append(").strength(").append(block.getStrengthOne()).append("f).luminance(").append(block.getLightLevel()).append(")\n")
.append("\t\t\t\t\t.hardness(").append(block.getExplosionResistance()).append(")");
if (block.isRequiresCorrectTool()) {
registration.append(".requiresTool()");
Expand Down
Loading

0 comments on commit 698b5db

Please sign in to comment.