teleport scroll

This commit is contained in:
Jenny 2025-03-20 11:00:11 +01:00
commit a93b0858bc
Signed by: Jenny
GPG Key ID: 2072A14E40940632
21 changed files with 889 additions and 0 deletions

208
build.gradle Normal file
View File

@ -0,0 +1,208 @@
buildscript {
repositories {
// These repositories are only for Gradle plugins, put any other repositories in the repository block further below
maven { url = 'https://repo.spongepowered.org/repository/maven-public/' }
mavenCentral()
}
dependencies {
classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
}
}
plugins {
id 'eclipse'
id 'idea'
id 'net.minecraftforge.gradle' version '[6.0.16,6.2)'
id 'org.parchmentmc.librarian.forgegradle' version '1.+'
}
apply plugin: 'org.spongepowered.mixin'
group = mod_group_id
version = mod_version
base {
archivesName = mod_id
}
java {
toolchain.languageVersion = JavaLanguageVersion.of(17)
}
minecraft {
// The mappings can be changed at any time and must be in the following format.
// Channel: Version:
// official MCVersion Official field/method names from Mojang mapping files
// parchment YYYY.MM.DD-MCVersion Open community-sourced parameter names and javadocs layered on top of official
//
// You must be aware of the Mojang license when using the 'official' or 'parchment' mappings.
// See more information here: https://github.com/MinecraftForge/MCPConfig/blob/master/Mojang.md
//
// Parchment is an unofficial project maintained by ParchmentMC, separate from MinecraftForge
// Additional setup is needed to use their mappings: https://parchmentmc.org/docs/getting-started
//
// Use non-default mappings at your own risk. They may not always work.
// Simply re-run your setup task after changing the mappings to update your workspace.
mappings channel: mapping_channel, version: mapping_version
// When true, this property will have all Eclipse/IntelliJ IDEA run configurations run the "prepareX" task for the given run configuration before launching the game.
// In most cases, it is not necessary to enable.
// enableEclipsePrepareRuns = true
// enableIdeaPrepareRuns = true
// This property allows configuring Gradle's ProcessResources task(s) to run on IDE output locations before launching the game.
// It is REQUIRED to be set to true for this template to function.
// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html
copyIdeResources = true
// When true, this property will add the folder name of all declared run configurations to generated IDE run configurations.
// The folder name can be set on a run configuration using the "folderName" property.
// By default, the folder name of a run configuration is the name of the Gradle project containing it.
// generateRunFolders = true
// This property enables access transformers for use in development.
// They will be applied to the Minecraft artifact.
// The access transformer file can be anywhere in the project.
// However, it must be at "META-INF/accesstransformer.cfg" in the final mod jar to be loaded by Forge.
// This default location is a best practice to automatically put the file in the right place in the final jar.
// See https://docs.minecraftforge.net/en/latest/advanced/accesstransformers/ for more information.
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
// applies to all the run configs below
configureEach {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
// The markers can be added/remove as needed separated by commas.
// "SCAN": For mods scan.
// "REGISTRIES": For firing of registry events.
// "REGISTRYDUMP": For getting the contents of all registries.
property 'forge.logging.markers', 'REGISTRIES'
// Recommended logging level for the console
// You can set various levels here.
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
property 'forge.logging.console.level', 'debug'
mods {
"${mod_id}" {
source sourceSets.main
}
}
}
client {
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
property 'forge.enabledGameTestNamespaces', mod_id
}
server {
property 'forge.enabledGameTestNamespaces', mod_id
args '--nogui'
}
// This run config launches GameTestServer and runs all registered gametests, then exits.
// By default, the server will crash when no gametests are provided.
// The gametest system is also enabled by default for other run configs under the /test command.
gameTestServer {
property 'forge.enabledGameTestNamespaces', mod_id
}
data {
// example of overriding the workingDirectory set in configureEach above
workingDirectory project.file('run-data')
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
}
}
}
mixin {
add sourceSets.main, "${mod_id}.refmap.json"
config "${mod_id}.mixins.json"
}
// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }
repositories {
// Put repositories for dependencies here
// ForgeGradle automatically adds the Forge maven and Maven Central for you
// If you have mod jar dependencies in ./libs, you can declare them as a repository like so.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html#sub:flat_dir_resolver
// flatDir {
// dir 'libs'
// }
}
dependencies {
// Specify the version of Minecraft to use.
// Any artifact can be supplied so long as it has a "userdev" classifier artifact and is a compatible patcher artifact.
// The "userdev" classifier will be requested and setup by ForgeGradle.
// If the group id is "net.minecraft" and the artifact id is one of ["client", "server", "joined"],
// then special handling is done to allow a setup of a vanilla dependency without the use of an external repository.
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
// Example mod dependency with JEI - using fg.deobf() ensures the dependency is remapped to your development mappings
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}-common-api:${jei_version}")
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}-forge-api:${jei_version}")
// runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}-forge:${jei_version}")
// Example mod dependency using a mod jar from ./libs with a flat dir repository
// This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar
// The group id is ignored when searching -- in this case, it is "blank"
// implementation fg.deobf("blank:coolmod-${mc_version}:${coolmod_version}")
// For more info:
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
}
// This block of code expands all declared replace properties in the specified resource targets.
// A missing property will result in an error. Properties are expanded using ${} Groovy notation.
// When "copyIdeResources" is enabled, this will also run before the game launches in IDE environments.
// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html
tasks.named('processResources', ProcessResources).configure {
var replaceProperties = [minecraft_version : minecraft_version, minecraft_version_range: minecraft_version_range,
forge_version : forge_version, forge_version_range: forge_version_range,
loader_version_range: loader_version_range,
mod_id : mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version,
mod_authors : mod_authors, mod_description: mod_description,]
inputs.properties replaceProperties
filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) {
expand replaceProperties + [project: project]
}
}
// Example for how to get properties into the manifest for reading at runtime.
tasks.named('jar', Jar).configure {
manifest {
attributes(["Specification-Title" : mod_id,
"Specification-Vendor" : mod_authors,
"Specification-Version" : "1", // We are version 1 of ourselves
"Implementation-Title" : project.name,
"Implementation-Version" : project.jar.archiveVersion,
"Implementation-Vendor" : mod_authors,
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")])
}
// This is the preferred method to reobfuscate your jar file
finalizedBy 'reobfJar'
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
}

49
gradle.properties Normal file
View File

@ -0,0 +1,49 @@
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
# The Minecraft version must agree with the Forge version to get a valid artifact
minecraft_version=1.20.1
# The Minecraft version range can use any release version of Minecraft as bounds.
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.20.1,1.21)
# The Forge version must agree with the Minecraft version to get a valid artifact
forge_version=47.4.0
# The Forge version range can use any version of Forge as bounds or match the loader version range
forge_version_range=[47,)
# The loader version range can only use the major version of Forge/FML as bounds
loader_version_range=[47,)
# The mapping channel to use for mappings.
# The default set of supported mapping channels are ["official", "snapshot", "snapshot_nodoc", "stable", "stable_nodoc"].
# Additional mapping channels can be registered through the "channelProviders" extension in a Gradle plugin.
#
# | Channel | Version | |
# |-----------|----------------------|--------------------------------------------------------------------------------|
# | official | MCVersion | Official field/method names from Mojang mapping files |
# | parchment | YYYY.MM.DD-MCVersion | Open community-sourced parameter names and javadocs layered on top of official |
#
# You must be aware of the Mojang license when using the 'official' or 'parchment' mappings.
# See more information here: https://github.com/MinecraftForge/MCPConfig/blob/master/Mojang.md
#
# Parchment is an unofficial project maintained by ParchmentMC, separate from Minecraft Forge.
# Additional setup is needed to use their mappings, see https://parchmentmc.org/docs/getting-started
mapping_channel=parchment
# The mapping version to query from the mapping channel.
# This must match the format required by the mapping channel.
mapping_version=2023.09.03-1.20.1
# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63}
# Must match the String constant located in the main mod class annotated with @Mod.
mod_id=magic
# The human-readable display name for the mod.
mod_name=magic
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=All Rights Reserved
# The mod version. See https://semver.org/
mod_version=0.0.1
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
mod_group_id=com.jenny
# The authors of the mod. This is a simple text string that is used for display purposes in the mod list.
mod_authors=
# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list.
mod_description=

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

16
settings.gradle Normal file
View File

@ -0,0 +1,16 @@
pluginManagement {
repositories {
gradlePluginPortal()
maven {
name = 'MinecraftForge'
url = 'https://maven.minecraftforge.net/'
}
maven { url = 'https://maven.parchmentmc.org' }
}
}
plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0'
}
rootProject.name = 'magic'

View File

@ -0,0 +1,35 @@
package com.jenny.magic;
import com.jenny.magic.entities.entities;
import com.jenny.magic.items.items;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
// The value here should match an entry in the META-INF/mods.toml file
@Mod(Magic.MODID)
public class Magic {
public static final String MODID = "magic";
public Magic() {
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
MinecraftForge.EVENT_BUS.register(this);
entities.register(modEventBus);
items.register(modEventBus);
creativeTab.register(modEventBus);
}
@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public static class ClientModEvents {
@SubscribeEvent
public static void onClientSetup(FMLClientSetupEvent event) {
entities.registerRenderers();
}
}
}

View File

@ -0,0 +1,37 @@
package com.jenny.magic;
import com.jenny.magic.items.items;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.RegistryObject;
import java.util.Arrays;
import static com.jenny.magic.Magic.MODID;
public class creativeTab {
public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID);
public static final RegistryObject<CreativeModeTab> CREATIVE_TAB = CREATIVE_MODE_TABS.register(MODID, () -> CreativeModeTab.builder().withTabsBefore(CreativeModeTabs.SPAWN_EGGS).icon(() -> items.WAND_HURTFUL.get().getDefaultInstance()).displayItems((parameters, output) -> {
output.acceptAll(Arrays.stream(getItems()).toList());
}).title(Component.literal("Magic")).build());
public static void register(IEventBus bus) {
CREATIVE_MODE_TABS.register(bus);
}
public static ItemStack[] getItems() {
ItemStack[] ret = new ItemStack[items.ITEMS.getEntries().size()];
int i = 0;
for (RegistryObject<Item> item : items.ITEMS.getEntries()) {
ret[i] = item.get().getDefaultInstance();
i++;
}
return ret;
}
}

View File

@ -0,0 +1,82 @@
package com.jenny.magic.entities;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
public abstract class BaseWandProjectile extends AbstractArrow {
protected BaseWandProjectile(EntityType<? extends AbstractArrow> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
}
public void shootFromRotation(Entity pShooter, float pX, float pY, float pZ, float pVelocity) {
this.setPos(pShooter.position().x, pShooter.getEyeY() - 0.1, pShooter.position().z);
float f = -Mth.sin(pY * ((float) Math.PI / 180F)) * Mth.cos(pX * ((float) Math.PI / 180F));
float f1 = -Mth.sin((pX + pZ) * ((float) Math.PI / 180F));
float f2 = Mth.cos(pY * ((float) Math.PI / 180F)) * Mth.cos(pX * ((float) Math.PI / 180F));
Vec3 vec = new Vec3(f, f1, f2).multiply(pVelocity, pVelocity, pVelocity);
this.setPos(pShooter.position().x, pShooter.getEyeY() - 0.1, pShooter.position().z);
this.setPos(new Vec3(pShooter.getX(), pShooter.getEyeY() - 0.1, pShooter.getZ()).add(vec.scale(1)));
this.setDeltaMovement(vec);
Vec3 vec3 = pShooter.getDeltaMovement();
this.setDeltaMovement(this.getDeltaMovement().add(vec3.x, pShooter.onGround() ? 0.0D : vec3.y, vec3.z));
}
public void tick() {
if (inGroundTime > 1) {
discard();
}
super.tick();
if (level().isClientSide) {
spawnParticles();
}
}
@Override
protected void onHitEntity(@NotNull EntityHitResult pResult) {
System.out.println(level().isClientSide);
if (level().isClientSide) {
hitParticles();
}
hitEntity(pResult);
//this.discard();
}
@Override
protected void onHitBlock(@NotNull BlockHitResult pResult) {
System.out.println(level().isClientSide);
if (level().isClientSide) {
hitParticles();
}
super.onHitBlock(pResult);
//this.discard();
}
protected Vec3 particlePos(double dist) {
return new Vec3(
level().getRandom().nextIntBetweenInclusive(-100, 100),
level().getRandom().nextIntBetweenInclusive(-100, 100),
level().getRandom().nextIntBetweenInclusive(-100, 100)
).normalize().scale(dist + ((double) level().getRandom().nextIntBetweenInclusive(0, 100) / 100)).add(position());
}
public void spawnParticles() {
}
protected void hitEntity(EntityHitResult pResult) {
}
protected void hitBlock(BlockHitResult pResult) {
}
public void hitParticles() {
}
public abstract String name();
}

View File

@ -0,0 +1,57 @@
package com.jenny.magic.entities;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
public class HurtfulProjectile extends BaseWandProjectile {
public HurtfulProjectile(EntityType<? extends BaseWandProjectile> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
}
public HurtfulProjectile(Level pLevel) {
super(entities.PROJECTILE_HURTFUL.get(), pLevel);
}
public String name() {
return "hurtful_projectile";
}
@Override
protected void hitEntity(@NotNull EntityHitResult pResult) {
if (pResult.getEntity() instanceof LivingEntity) {
Entity owner = this.getOwner();
DamageSource damagesource;
if (owner == null) {
damagesource = this.damageSources().arrow(this, this);
} else {
damagesource = this.damageSources().arrow(this, owner);
if (owner instanceof LivingEntity) {
((LivingEntity) owner).setLastHurtMob(pResult.getEntity());
}
}
pResult.getEntity().hurt(this.damageSources().arrow(this, this.getOwner()), 5);
this.doPostHurtEffects((LivingEntity) pResult.getEntity());
}
}
@Override
public void hitParticles() {
for (int i = 0; i < 20; i++) {
Vec3 particlePos = particlePos(2);
level().addParticle(ParticleTypes.LAVA, particlePos.x, particlePos.y, particlePos.z, 0, 0, 0);
}
}
@Override
protected ItemStack getPickupItem() {
return ItemStack.EMPTY;
}
}

View File

@ -0,0 +1,39 @@
package com.jenny.magic.entities.client;
import com.jenny.magic.entities.BaseWandProjectile;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.TntMinecartRenderer;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Blocks;
import org.jetbrains.annotations.NotNull;
public class BaseProjectileRenderer<T extends BaseWandProjectile> extends EntityRenderer<T> {
private final BlockRenderDispatcher blockRenderer;
public BaseProjectileRenderer(EntityRendererProvider.Context pContext) {
super(pContext);
this.blockRenderer = pContext.getBlockRenderDispatcher();
}
public void render(@NotNull T pEntity, float pEntityYaw, float pPartialTicks, @NotNull PoseStack pPoseStack, @NotNull MultiBufferSource pBuffer, int pPackedLight) {
pPoseStack.pushPose();
pPoseStack.mulPose(Axis.YP.rotationDegrees(-90.0F));
pPoseStack.scale(pEntity.getBbWidth(), pEntity.getBbHeight(), pEntity.getBbWidth());
pPoseStack.mulPose(Axis.YP.rotationDegrees(90.0F));
TntMinecartRenderer.renderWhiteSolidBlock(this.blockRenderer, Blocks.TNT.defaultBlockState(), pPoseStack, pBuffer, pPackedLight, false);
pPoseStack.popPose();
super.render(pEntity, pEntityYaw, pPartialTicks, pPoseStack, pBuffer, pPackedLight);
}
@Override
public @NotNull ResourceLocation getTextureLocation(T pEntity) {
//return new ResourceLocation(MOD_ID, String.format("textures/entity/%s.png", pEntity.name()));
return TextureAtlas.LOCATION_BLOCKS;
}
}

View File

@ -0,0 +1,29 @@
package com.jenny.magic.entities;
import com.jenny.magic.entities.client.BaseProjectileRenderer;
import net.minecraft.client.renderer.entity.EntityRenderers;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import static com.jenny.magic.Magic.MODID;
public class entities {
public static final DeferredRegister<EntityType<?>> ENTITY_TYPES =
DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, MODID);
public static final RegistryObject<EntityType<HurtfulProjectile>> PROJECTILE_HURTFUL =
ENTITY_TYPES.register("projectile_hurtful", () -> EntityType.Builder.<HurtfulProjectile>of(HurtfulProjectile::new, MobCategory.MISC)
.sized(0.3F, 0.3F).fireImmune().clientTrackingRange(8).build("projectile_hurtful"));
public static void register(IEventBus eventBus) {
ENTITY_TYPES.register(eventBus);
}
public static void registerRenderers() {
EntityRenderers.register(PROJECTILE_HURTFUL.get(), BaseProjectileRenderer::new);
}
}

View File

@ -0,0 +1,56 @@
package com.jenny.magic.items;
import net.minecraft.ChatFormatting;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import static com.jenny.magic.Magic.MODID;
abstract class BaseItem extends Item {
public BaseItem(Properties pProperties) {
super(pProperties);
}
@Override
public void appendHoverText(@NotNull ItemStack pStack, @Nullable Level pLevel, @NotNull List<Component> pTooltipComponents, @NotNull TooltipFlag pIsAdvanced) {
String key = String.format("tooltip.%s.%s", MODID, this);
MutableComponent toolTip = Component.translatable(key);
if (!toolTip.getString().equals(key)) {
pTooltipComponents.add(toolTip.withStyle(ChatFormatting.DARK_BLUE));
super.appendHoverText(pStack, pLevel, pTooltipComponents, pIsAdvanced);
}
}
public void spawnParticles(@NotNull Level level, Vec3 pos, int count, double size, ParticleOptions particle, ParticleDirection direction) {
RandomSource rng = level.getRandom();
Vec3 position;
Vec3 delta;
for (int i = 0; i < count; i++) {
delta = new Vec3(rng.nextIntBetweenInclusive(-100, 100), rng.nextIntBetweenInclusive(-100, 100), rng.nextIntBetweenInclusive(-100, 100)).normalize().scale(size);
if (direction == ParticleDirection.OUTWARD) {
position = pos;
} else {
position = pos.subtract(delta);
delta = delta.scale(0.02 * size);
}
level.addParticle(particle, position.x, position.y, position.z, delta.x, delta.y, delta.z);
}
}
enum ParticleDirection {
INWARD,
OUTWARD
}
}

View File

@ -0,0 +1,26 @@
package com.jenny.magic.items;
import com.jenny.magic.entities.BaseWandProjectile;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
abstract class BaseWand extends BaseItem {
public BaseWand(Properties properties) {
super(properties.stacksTo(1));
}
@Override
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level pLevel, Player pPlayer, @NotNull InteractionHand pUsedHand) {
ItemStack itemstack = pPlayer.getItemInHand(pUsedHand);
BaseWandProjectile projectile = newProjectile(pLevel);
projectile.shootFromRotation(pPlayer, pPlayer.getXRot(), pPlayer.getYRot(), 0.0F, 2.0F);
pLevel.addFreshEntity(projectile);
return InteractionResultHolder.success(itemstack);
}
abstract BaseWandProjectile newProjectile(Level level);
}

View File

@ -0,0 +1,16 @@
package com.jenny.magic.items;
import com.jenny.magic.entities.BaseWandProjectile;
import com.jenny.magic.entities.HurtfulProjectile;
import net.minecraft.world.level.Level;
public class HurtfulWand extends BaseWand {
public HurtfulWand(Properties p_41383_) {
super(p_41383_);
}
@Override
BaseWandProjectile newProjectile(Level level) {
return new HurtfulProjectile(level);
}
}

View File

@ -0,0 +1,101 @@
package com.jenny.magic.items;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import static com.jenny.magic.Magic.MODID;
public class TeleportScroll extends BaseItem {
public TeleportScroll(Properties pProperties) {
super(pProperties);
}
@Override
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level pLevel, @NotNull Player pPlayer, @NotNull InteractionHand pUsedHand) {
use(pPlayer.position(), pPlayer, pPlayer.getItemInHand(pUsedHand), pLevel);
return InteractionResultHolder.success(pPlayer.getItemInHand(pUsedHand));
}
@Override
public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {
use(pContext.getClickedPos().getCenter().add(0, 0.5, 0), pContext.getPlayer(), pContext.getItemInHand(), pContext.getLevel());
return InteractionResult.SUCCESS;
}
protected void use(Vec3 pos, Player player, @NotNull ItemStack itemStack, Level level) {
if (itemStack.getTag() == null) {
itemStack.setTag(new CompoundTag());
}
if (locationSet(itemStack.getTag()) && !player.isCrouching()) {
if (level.isClientSide) {
spawnParticles(level, player.position().add(0, player.getEyeHeight(), 0), 20, 5, ParticleTypes.POOF, ParticleDirection.INWARD);
}
player.setPos(getLocation(itemStack.getTag()));
if (level.isClientSide) {
spawnParticles(level, player.position().add(0, player.getEyeHeight(), 0), 20, 0.2, ParticleTypes.END_ROD, ParticleDirection.OUTWARD);
}
} else {
itemStack.setTag(setLocation(pos, itemStack.getTag()));
if (level.isClientSide) {
MessageLocationSet();
}
}
}
private boolean locationSet(@NotNull CompoundTag cTag) {
return cTag.contains("teleport_x") && cTag.contains("teleport_y") && cTag.contains("teleport_z");
}
private CompoundTag setLocation(@NotNull Vec3 playerPos, @NotNull CompoundTag cTag) {
cTag.putDouble("teleport_x", playerPos.x);
cTag.putDouble("teleport_y", playerPos.y);
cTag.putDouble("teleport_z", playerPos.z);
return cTag;
}
private Vec3 getLocation(@NotNull CompoundTag cTag) {
return new Vec3(
cTag.getDouble("teleport_x"),
cTag.getDouble("teleport_y"),
cTag.getDouble("teleport_z")
);
}
@Override
public void appendHoverText(@NotNull ItemStack pStack, @Nullable Level pLevel, @NotNull List<Component> pTooltipComponents, @NotNull TooltipFlag pIsAdvanced) {
if (pStack.getTag() != null && locationSet(pStack.getTag())) {
String key = String.format("tooltip.%s.scroll_teleport.set", MODID);
MutableComponent toolTip = Component.translatable(key);
Vec3 pos = getLocation(pStack.getTag());
MutableComponent toolTipPos = Component.literal((int) pos.x + ";" + (int) pos.y + ";" + (int) pos.z);
pTooltipComponents.add(toolTip.withStyle(ChatFormatting.DARK_BLUE).append(toolTipPos.withStyle(ChatFormatting.WHITE)));
} else {
String key = String.format("tooltip.%s.scroll_teleport.unset", MODID);
MutableComponent toolTip = Component.translatable(key);
pTooltipComponents.add(toolTip.withStyle(ChatFormatting.DARK_BLUE));
}
}
protected void MessageLocationSet() {
Minecraft.getInstance().player.sendSystemMessage(Component.translatable(String.format("message.%s.scroll_teleport.set", MODID)));
}
}

View File

@ -0,0 +1,20 @@
package com.jenny.magic.items;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
public class TeleportScrollConsumable extends TeleportScroll {
public TeleportScrollConsumable(Properties pProperties) {
super(pProperties);
}
@Override
protected void use(Vec3 pos, Player player, @NotNull ItemStack itemStack, Level level) {
super.use(pos, player, itemStack, level);
itemStack.shrink(1);
}
}

View File

@ -0,0 +1,20 @@
package com.jenny.magic.items;
import net.minecraft.world.item.Item;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import static com.jenny.magic.Magic.MODID;
public class items {
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
public static final RegistryObject<Item> WAND_HURTFUL = ITEMS.register("wand_hurtful", () -> new HurtfulWand(new Item.Properties()));
public static final RegistryObject<Item> SCROLL_TELEPORT = ITEMS.register("scroll_teleport", () -> new TeleportScroll(new Item.Properties().stacksTo(1)));
public static final RegistryObject<Item> SCROLL_TELEPORT_CONSUME = ITEMS.register("scroll_teleport_consume", () -> new TeleportScrollConsumable(new Item.Properties().stacksTo(16)));
public static void register(IEventBus bus) {
ITEMS.register(bus);
}
}

View File

@ -0,0 +1,63 @@
# This is an example mods.toml file. It contains the data relating to the loading mods.
# There are several mandatory fields (#mandatory), and many more that are optional (#optional).
# The overall format is standard TOML format, v0.5.0.
# Note that there are a couple of TOML lists in this file.
# Find more information on toml format here: https://github.com/toml-lang/toml
# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
modLoader = "javafml" #mandatory
# A version range to match for said mod loader - for regular FML @Mod it will be the forge version
loaderVersion = "${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions.
# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties.
# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here.
license = "${mod_license}"
# A URL to refer people to when problems occur with this mod
#issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional
# A list of mods - how many allowed here is determined by the individual mod loader
[[mods]] #mandatory
# The modid of the mod
modId = "${mod_id}" #mandatory
# The version number of the mod
version = "${mod_version}" #mandatory
# A display name for the mod
displayName = "${mod_name}" #mandatory
# A URL to query for updates for this mod. See the JSON update specification https://docs.minecraftforge.net/en/latest/misc/updatechecker/
#updateJSONURL="https://change.me.example.invalid/updates.json" #optional
# A URL for the "homepage" for this mod, displayed in the mod UI
#displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional
# A file name (in the root of the mod JAR) containing a logo for display
#logoFile="magic.png" #optional
# A text field displayed in the mod UI
#credits="Thanks for this example mod goes to Java" #optional
# A text field displayed in the mod UI
authors = "${mod_authors}" #optional
# Display Test controls the display for your mod in the server connection screen
# MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod.
# IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod.
# IGNORE_ALL_VERSION means that your mod will not cause a red X if it's present on the client or the server. This is a special case and should only be used if your mod has no server component.
# NONE means that no display test is set on your mod. You need to do this yourself, see IExtensionPoint.DisplayTest for more information. You can define any scheme you wish with this value.
# IMPORTANT NOTE: this is NOT an instruction as to which environments (CLIENT or DEDICATED SERVER) your mod loads on. Your mod should load (and maybe do nothing!) whereever it finds itself.
#displayTest="MATCH_VERSION" # MATCH_VERSION is the default if nothing is specified (#optional)
# The description text for the mod (multi line!) (#mandatory)
description = '''${mod_description}'''
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
[[dependencies."${mod_id}"]] #optional
# the modid of the dependency
modId = "forge" #mandatory
# Does this dependency have to exist - if not, ordering below must be specified
mandatory = true #mandatory
# The version range of the dependency
versionRange = "${forge_version_range}" #mandatory
# An ordering relationship for the dependency - BEFORE or AFTER required if the dependency is not mandatory
# BEFORE - This mod is loaded BEFORE the dependency
# AFTER - This mod is loaded AFTER the dependency
ordering = "NONE"
# Side this dependency is applied on - BOTH, CLIENT, or SERVER
side = "BOTH"# Here's another dependency
[[dependencies."${mod_id}"]]
modId = "minecraft"
mandatory = true
# This version range declares a minimum of the current minecraft version up to but not including the next major version
versionRange = "${minecraft_version_range}"
ordering = "NONE"
side = "BOTH"

View File

@ -0,0 +1,8 @@
{
"item.magic.scroll_teleport": "Teleport scroll",
"item.magic.scroll_teleport_consume": "Brittle teleport scroll",
"tooltip.magic.scroll_teleport.unset": "no location set",
"tooltip.magic.scroll_teleport.set": "teleports to: ",
"message.magic.scroll_teleport.set": "location set"
}

View File

@ -0,0 +1,14 @@
{
"required": true,
"minVersion": "0.8",
"package": "com.jenny.magic.mixin",
"compatibilityLevel": "JAVA_8",
"refmap": "magic.refmap.json",
"mixins": [
],
"client": [
],
"injectors": {
"defaultRequire": 1
}
}

View File

@ -0,0 +1,6 @@
{
"pack": {
"description": "magic resources",
"pack_format": 15
}
}