Skip to content

Commit

Permalink
cool new stuff!
Browse files Browse the repository at this point in the history
  • Loading branch information
froyo4u committed Apr 21, 2021
1 parent 7b4d185 commit 62920d0
Show file tree
Hide file tree
Showing 21 changed files with 1,038 additions and 490 deletions.
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ allprojects {
}
maven { url 'https://hephaestus.dev/release' }
maven { url 'https://repo.repsy.io/mvn/gandiber/geckolib' }
maven { url 'https://maven.shedaniel.me' }
maven { url 'https://maven.fabricmc.net/io/github/prospector/modmenu' }

jcenter()
}
Expand Down Expand Up @@ -53,6 +55,12 @@ allprojects {
modImplementation 'software.bernie.geckolib:geckolib-fabric-1.16.5:3.0.30:dev'
include 'software.bernie.geckolib:geckolib-fabric-1.16.5:3.0.30:dev'

modImplementation('io.github.prospector:modmenu:1.16.9')

modImplementation("me.shedaniel.cloth:cloth-config-fabric:4.11.14") {
exclude(group: "net.fabricmc.fabric-api")
}

// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/tk/meowmc/portalgun/Portalgun.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import tk.meowmc.portalgun.config.PortalGunConfig;
import tk.meowmc.portalgun.items.PortalGunItem;

public class Portalgun implements ModInitializer {
Expand All @@ -33,9 +34,11 @@ public class Portalgun implements ModInitializer {
public static SoundEvent PORTAL_CLOSE_EVENT = new SoundEvent(PORTAL_CLOSE);

public static Logger LOGGER = LogManager.getLogger();

public static void logString(Level level, String message) {
LOGGER.log(level, "[" + MOD_NAME + "] " + message);
}

public static void logInt(Level level, int message) {
LOGGER.log(level, "[" + MOD_NAME + "] " + message);
}
Expand All @@ -55,6 +58,8 @@ public void onInitialize() {
Registry.register(Registry.SOUND_EVENT, PORTAL2_SHOOT, PORTAL2_SHOOT_EVENT);
Registry.register(Registry.SOUND_EVENT, PORTAL_OPEN, PORTAL_OPEN_EVENT);
Registry.register(Registry.SOUND_EVENT, PORTAL_CLOSE, PORTAL_CLOSE_EVENT);

PortalGunConfig.register();
}


Expand Down
5 changes: 5 additions & 0 deletions src/main/java/tk/meowmc/portalgun/client/PortalgunClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import net.minecraft.client.options.KeyBinding;
import net.minecraft.client.util.InputUtil;
import org.lwjgl.glfw.GLFW;
import software.bernie.geckolib3.renderer.geo.GeoItemRenderer;
import tk.meowmc.portalgun.Portalgun;
import tk.meowmc.portalgun.client.renderer.PortalGunRenderer;

@Environment(EnvType.CLIENT)
public class PortalgunClient implements ClientModInitializer {
Expand Down Expand Up @@ -44,5 +47,7 @@ public void onInitializeClient() {
}
}
});

GeoItemRenderer.registerItemRenderer(Portalgun.PORTALGUN, new PortalGunRenderer());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package tk.meowmc.portalgun.client.renderer;

import software.bernie.geckolib3.renderer.geo.GeoItemRenderer;
import tk.meowmc.portalgun.client.renderer.models.PortalGunModel;
import tk.meowmc.portalgun.items.PortalGunItem;

public class PortalGunRenderer extends GeoItemRenderer<PortalGunItem> {
public PortalGunRenderer() {
super(new PortalGunModel());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package tk.meowmc.portalgun.client.renderer.models;

import me.shedaniel.autoconfig.AutoConfig;
import net.minecraft.util.Identifier;
import software.bernie.geckolib3.model.AnimatedGeoModel;
import tk.meowmc.portalgun.config.PortalGunConfig;
import tk.meowmc.portalgun.items.PortalGunItem;

import static tk.meowmc.portalgun.Portalgun.id;

public class PortalGunModel extends AnimatedGeoModel<PortalGunItem> {
PortalGunConfig config = AutoConfig.getConfigHolder(PortalGunConfig.class).getConfig();

@Override
public Identifier getModelLocation(PortalGunItem object) {
/*if (config.enabled.enableOldPortalGunModel)
return id("geo/portalgun_og.geo.json");
else*/
return id("geo/portalgun.geo.json");
}

@Override
public Identifier getTextureLocation(PortalGunItem object) {
/*if (config.enabled.enableOldPortalGunModel)
return id("textures/item/portal_gun_og.png");
else*/
return id("textures/item/portal_gun.png");
}

@Override
public Identifier getAnimationFileLocation(PortalGunItem animatable) {
/*if (config.enabled.enableOldPortalGunModel)
return id("animations/portalgun_og.animation.json");
else*/
return id("animations/portalgun.animation.json");
}
}
12 changes: 12 additions & 0 deletions src/main/java/tk/meowmc/portalgun/config/ModMenuIntegration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package tk.meowmc.portalgun.config;

import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import me.shedaniel.autoconfig.AutoConfig;

public class ModMenuIntegration implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return parent -> AutoConfig.getConfigScreen(PortalGunConfig.class, parent).get();
}
}
34 changes: 34 additions & 0 deletions src/main/java/tk/meowmc/portalgun/config/PortalGunConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package tk.meowmc.portalgun.config;

import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.ConfigData;
import me.shedaniel.autoconfig.annotation.Config;
import me.shedaniel.autoconfig.annotation.ConfigEntry;
import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer;
import tk.meowmc.portalgun.Portalgun;

@Config(name = Portalgun.MODID)
public class PortalGunConfig implements ConfigData {
@ConfigEntry.Gui.TransitiveObject
@ConfigEntry.Category("enabled")
public final Enabled enabled = new Enabled();

public static void register() {
AutoConfig.register(PortalGunConfig.class, JanksonConfigSerializer::new);
}

public static PortalGunConfig get() {
return AutoConfig.getConfigHolder(PortalGunConfig.class).getConfig();
}

public static void save() {
AutoConfig.getConfigHolder(PortalGunConfig.class).save();
}


public static class Enabled {
/*public final boolean enableOldPortalGunModel = false;*/
public final boolean enableRoundPortals = true;
}

}
6 changes: 6 additions & 0 deletions src/main/java/tk/meowmc/portalgun/ducks/IEEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package tk.meowmc.portalgun.ducks;

public interface IEEntity {
long collidingPortalActiveTickTime = 0;
int age = 0;
}
116 changes: 78 additions & 38 deletions src/main/java/tk/meowmc/portalgun/items/PortalGunItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World;
import software.bernie.geckolib3.core.IAnimatable;
import software.bernie.geckolib3.core.PlayState;
import software.bernie.geckolib3.core.builder.AnimationBuilder;
import software.bernie.geckolib3.core.controller.AnimationController;
import software.bernie.geckolib3.core.event.predicate.AnimationEvent;
import software.bernie.geckolib3.core.manager.AnimationData;
import software.bernie.geckolib3.core.manager.AnimationFactory;
import software.bernie.geckolib3.util.GeckoLibUtil;
import tk.meowmc.portalgun.Portalgun;
import tk.meowmc.portalgun.client.PortalgunClient;
import tk.meowmc.portalgun.misc.PortalMethods;
Expand All @@ -34,8 +42,10 @@
import static net.minecraft.util.hit.HitResult.Type.MISS;
import static tk.meowmc.portalgun.misc.PortalMethods.*;

public class PortalGunItem extends Item {
public class PortalGunItem extends Item implements IAnimatable {
public static final String KEY = Portalgun.MODID + ":portalgun_portals";
public String controllerName = "portalgunController";
public AnimationFactory factory = new AnimationFactory(this);
public static HitResult hit;
public static BlockHitResult blockHit;
public static BlockPos blockPos;
Expand All @@ -62,15 +72,33 @@ public PortalGunItem(Settings settings) {
super(settings);
}

public static void removeOldPortals(CompoundTag tag, CompoundTag portalsTag, Entity portal1, Entity portal2) {
if (portal1 != null && portal2 != null) {
private <P extends Item & IAnimatable> PlayState predicate(AnimationEvent<P> event) {
return PlayState.CONTINUE;
}

@Override
public void registerControllers(AnimationData animationData) {
AnimationController controller = new AnimationController(this, controllerName, 1, this::predicate);
animationData.addAnimationController(controller);
}

@Override
public AnimationFactory getFactory() {
return this.factory;
}

public static void removeOldPortals(CompoundTag tag, CompoundTag portalsTag, Entity portal1, Entity portal2, World world) {
if (portal1 != null) {
portal1.kill();
portalsTag.remove("Left" + "Portal");
newPortal1.removed = false;
}
if (portal2 != null) {
portal2.kill();
portalsTag.remove("Right" + "Portal");
newPortal2.removed = false;
}
portalsTag.remove("Left" + "Portal");
portalsTag.remove("Right" + "Portal");
newPortal1.removed = false;
newPortal2.removed = false;
tag.remove(world.getRegistryKey().toString());
}

@Override
Expand Down Expand Up @@ -98,6 +126,8 @@ public void portal1Spawn(World world, PlayerEntity user, Hand hand) {
blockHit = (BlockHitResult) hit;
blockPos = blockHit.getBlockPos();
blockState = world.getBlockState(blockPos);
AnimationController controller = GeckoLibUtil.getControllerForStack(factory, itemStack, controllerName);


if (hit.getType() == BLOCK && PortalgunClient.delay) {
direction = blockHit.getSide();
Expand Down Expand Up @@ -198,21 +228,24 @@ public void portal1Spawn(World world, PlayerEntity user, Hand hand) {
SoundCategory.NEUTRAL,
1.0F,
1F);


controller.markNeedsReload();
controller.transitionLengthTicks = 3;
controller.setAnimation(new AnimationBuilder().addAnimation("portal_shoot", false));

if (portalsTag.contains("Left" + "Portal")) {
newPortal1 = (Portal) ((ServerWorld) world).getEntity(portalsTag.getUuid("Left" + "Portal"));
if (newPortal1 != null) {
portal1 = newPortal1.world != null ? (Portal) ((ServerWorld) newPortal1.world).getEntity(portalsTag.getUuid("Left" + "Portal")) : (Portal) ((ServerWorld) world).getEntity(portalsTag.getUuid("Left" + "Portal"));
if (portal1 == null)
newPortal1 = Portal.entityType.create(McHelper.getServer().getWorld(world.getRegistryKey()));
else
portal1Exists = true;
}
}

if (portalsTag.contains("Right" + "Portal")) {
newPortal2 = (Portal) ((ServerWorld) world).getEntity(portalsTag.getUuid("Right" + "Portal"));
if (newPortal2 != null) {
portal2 = newPortal2.world != null ? (Portal) ((ServerWorld) newPortal2.world).getEntity(portalsTag.getUuid("Right" + "Portal")) : (Portal) ((ServerWorld) world).getEntity(portalsTag.getUuid("Right" + "Portal"));
if (portal2 == null)
newPortal2 = Portal.entityType.create(McHelper.getServer().getWorld(world.getRegistryKey()));
else
portal2Exists = true;
}
}

if (notSnowUp(direction) || isSnowUp(direction)) {
Expand All @@ -232,10 +265,6 @@ public void portal1Spawn(World world, PlayerEntity user, Hand hand) {

ModMain.serverTaskList.addTask(TaskList.withDelay(delay, TaskList.oneShotTask(() -> {
if (McHelper.getServer().getThread() == Thread.currentThread()) {
if (portalsTag.contains("Left" + "Portal") && portalsTag.contains("Right" + "Portal")) {
portal1 = (Portal) ((ServerWorld) world).getEntity(portalsTag.getUuid("Left" + "Portal"));
portal2 = (Portal) ((ServerWorld) world).getEntity(portalsTag.getUuid("Right" + "Portal"));
}
world.playSound(null,
newPortal1.getX(),
newPortal1.getY(),
Expand All @@ -244,9 +273,14 @@ public void portal1Spawn(World world, PlayerEntity user, Hand hand) {
SoundCategory.NEUTRAL,
1.0F,
1F);
removeOldPortals(tag, portalsTag, portal1, portal2);
McHelper.spawnServerEntity(newPortal1);
McHelper.spawnServerEntity(newPortal2);
if (!portal1Exists && !portal2Exists) {
removeOldPortals(tag, portalsTag, portal1, portal2, world);
McHelper.spawnServerEntity(newPortal1);
McHelper.spawnServerEntity(newPortal2);
} else {
newPortal1.reloadAndSyncToClient();
newPortal2.reloadAndSyncToClient();
}
}
waitPortal = false;
if (newPortal2 != null) {
Expand Down Expand Up @@ -276,6 +310,7 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand han
blockHit = (BlockHitResult) hit;
blockPos = blockHit.getBlockPos();
blockState = world.getBlockState(blockPos);
AnimationController controller = GeckoLibUtil.getControllerForStack(this.factory, itemStack, controllerName);

if (hit.getType() == MISS)
return TypedActionResult.fail(itemStack);
Expand Down Expand Up @@ -361,12 +396,11 @@ else if (hit.getType() == BLOCK) {

int delay = (int) (0.5 * distance);

client.attackCooldown = 10;
client.gameRenderer.firstPersonRenderer.resetEquipProgress(user.getActiveHand());
controller.markNeedsReload();
controller.setAnimation(new AnimationBuilder().addAnimation("portal_shoot", false));

if (!world.isClient) {
if (!waitPortal && !space1BlockState.isOpaque() && space2BlockState.isOpaque() && !space3BlockState.isOpaque()) {

world.playSound(null,
user.getX(),
user.getY(),
Expand All @@ -378,16 +412,22 @@ else if (hit.getType() == BLOCK) {

if (portalsTag.contains("Left" + "Portal")) {
newPortal1 = (Portal) ((ServerWorld) world).getEntity(portalsTag.getUuid("Left" + "Portal"));
if (newPortal1 != null) {
portal1Exists = true;
if (portal1 == null) {
newPortal1 = Portal.entityType.create(McHelper.getServer().getWorld(world.getRegistryKey()));
portal1Exists = false;
}
else
portal1Exists = true;
}

if (portalsTag.contains("Right" + "Portal")) {
newPortal2 = (Portal) ((ServerWorld) world).getEntity(portalsTag.getUuid("Right" + "Portal"));
if (newPortal2 != null) {
portal2Exists = true;
if (newPortal2 == null) {
newPortal2 = Portal.entityType.create(McHelper.getServer().getWorld(world.getRegistryKey()));
portal2Exists = false;
}
else
portal2Exists = true;
}


Expand All @@ -402,10 +442,6 @@ else if (hit.getType() == BLOCK) {

ModMain.serverTaskList.addTask(TaskList.withDelay(delay, TaskList.oneShotTask(() -> {
if (McHelper.getServer().getThread() == Thread.currentThread()) {
if (portalsTag.contains("Left" + "Portal") && portalsTag.contains("Right" + "Portal")) {
portal1 = (Portal) ((ServerWorld) world).getEntity(portalsTag.getUuid("Left" + "Portal"));
portal2 = (Portal) ((ServerWorld) world).getEntity(portalsTag.getUuid("Right" + "Portal"));
}
world.playSound(null,
newPortal2.getX(),
newPortal2.getY(),
Expand All @@ -414,9 +450,14 @@ else if (hit.getType() == BLOCK) {
SoundCategory.NEUTRAL,
1.0F,
1F);
removeOldPortals(tag, portalsTag, portal1, portal2);
McHelper.spawnServerEntity(newPortal1);
McHelper.spawnServerEntity(newPortal2);
if (!portal1Exists && !portal2Exists) {
removeOldPortals(tag, portalsTag, portal1, portal2, world);
McHelper.spawnServerEntity(newPortal1);
McHelper.spawnServerEntity(newPortal2);
} else {
newPortal1.reloadAndSyncToClient();
newPortal2.reloadAndSyncToClient();
}
}
waitPortal = false;
if (newPortal2 != null) {
Expand All @@ -434,7 +475,6 @@ else if (hit.getType() == BLOCK) {
user.incrementStat(Stats.USED.getOrCreateStat(this));
}

return TypedActionResult.pass(itemStack);
return TypedActionResult.fail(itemStack);
}

}
Loading

0 comments on commit 62920d0

Please sign in to comment.