Skip to content

Commit

Permalink
Torcherino...
Browse files Browse the repository at this point in the history
  • Loading branch information
NinjaPhenix committed Mar 20, 2020
1 parent 9b86373 commit ef60e26
Show file tree
Hide file tree
Showing 112 changed files with 3,170 additions and 1 deletion.
2 changes: 2 additions & 0 deletions chainmail/src/main/java/ninjaphenix/chainmail/impl/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public void onInitialize()
// whilst may require some initial effort will mean there's no pre-release steps.
// would also shrink mod size by an insignificant amount.
// also would simplify the build process.
// negatives: delay switching between tests and code
// clutters root folder
if (DEBUG)
{
final ClassLoader loader = this.getClass().getClassLoader();
Expand Down
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ pluginManagement {
}
}

include 'chainmail'
include 'chainmail'
include 'torcherino'
11 changes: 11 additions & 0 deletions torcherino/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repositories {
maven { url "http://server.bbkr.space:8081/artifactory/libs-release/" }
}

dependencies {
compile project(path: ":chainmail")
include project(path: ":chainmail")

modImplementation "io.github.cottonmc:Jankson-Fabric:2.0.0+j1.2.0"
include "io.github.cottonmc:Jankson-Fabric:2.0.0+j1.2.0"
}
2 changes: 2 additions & 0 deletions torcherino/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod_id = torcherino
mod_version = 2.11.62
89 changes: 89 additions & 0 deletions torcherino/src/main/java/torcherino/Torcherino.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package torcherino;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.network.PacketContext;
import net.fabricmc.fabric.api.network.ServerSidePacketRegistry;
import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.particle.DefaultParticleType;
import net.minecraft.util.Identifier;
import net.minecraft.util.PacketByteBuf;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import torcherino.api.TorcherinoAPI;
import torcherino.api.blocks.entity.TorcherinoBlockEntity;
import torcherino.api.entrypoints.TorcherinoInitializer;
import torcherino.blocks.ModBlocks;
import torcherino.config.Config;

import java.util.ArrayList;
import java.util.HashSet;

@SuppressWarnings("SpellCheckingInspection")
public class Torcherino implements ModInitializer, TorcherinoInitializer
{
public static final String MOD_ID = "torcherino";
public static final Logger LOGGER = LogManager.getLogger(MOD_ID);
private static final HashSet<String> allowedUuids = new HashSet<>();
public static ArrayList<DefaultParticleType> particles = new ArrayList<>();

public static void playerConnected(String uuid) { allowedUuids.add(uuid); }

public static boolean hasIsOnline(String uuid) { return allowedUuids.contains(uuid); }

public static void playerDisconnect(String uuid) { if (Config.INSTANCE.online_mode.equals("ONLINE")) { allowedUuids.remove(uuid); } }

@Override
public void onInitialize()
{
Config.initialize();
TorcherinoAPI.INSTANCE.registerTier(new Identifier("null"), 4, 4, 4);
TorcherinoAPI.INSTANCE.getTiers().forEach((id, tier) ->
{
if (!id.getNamespace().equals(MOD_ID)) { return; }
String path = id.getPath() + "_flame";
if (path.equals("normal_flame")) { path = "flame"; }
particles.add(Registry.register(Registry.PARTICLE_TYPE, new Identifier(MOD_ID, path), FabricParticleTypes.simple()));
});
ModBlocks.INSTANCE.initialize();
ServerSidePacketRegistry.INSTANCE.register(new Identifier(Torcherino.MOD_ID, "utv"), (PacketContext context, PacketByteBuf buffer) ->
{
World world = context.getPlayer().getEntityWorld();
BlockPos pos = buffer.readBlockPos();
buffer.retain();
context.getTaskQueue().execute(() ->
{
try
{
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof TorcherinoBlockEntity) { ((TorcherinoBlockEntity) blockEntity).readClientData(buffer); }
}
finally
{
buffer.release();
}
});
});
FabricLoader.getInstance().getEntrypoints("torcherinoInitializer", TorcherinoInitializer.class).forEach(TorcherinoInitializer::onTorcherinoInitialize);
}

@Override
public void onTorcherinoInitialize()
{
TorcherinoAPI.INSTANCE.blacklistBlock(Blocks.WATER);
TorcherinoAPI.INSTANCE.blacklistBlock(Blocks.LAVA);
TorcherinoAPI.INSTANCE.blacklistBlock(Blocks.AIR);
TorcherinoAPI.INSTANCE.blacklistBlock(Blocks.CAVE_AIR);
TorcherinoAPI.INSTANCE.blacklistBlock(Blocks.VOID_AIR);
if (FabricLoader.getInstance().isModLoaded("computercraft"))
{
TorcherinoAPI.INSTANCE.blacklistBlockEntity(new Identifier("computercraft", "turtle_normal"));
TorcherinoAPI.INSTANCE.blacklistBlockEntity(new Identifier("computercraft", "turtle_advanced"));
}
}
}
79 changes: 79 additions & 0 deletions torcherino/src/main/java/torcherino/TorcherinoClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package torcherino;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback;
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
import net.fabricmc.fabric.api.network.PacketContext;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.particle.FlameParticle;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.PacketByteBuf;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import torcherino.api.Tier;
import torcherino.api.TierSupplier;
import torcherino.api.TorcherinoAPI;
import torcherino.api.blocks.entity.TorcherinoBlockEntity;
import torcherino.api.impl.TorcherinoImpl;
import torcherino.client.screen.TorcherinoScreen;

import java.util.HashMap;

import static torcherino.Torcherino.MOD_ID;

@SuppressWarnings("SpellCheckingInspection")
public class TorcherinoClient implements ClientModInitializer
{
@Override
public void onInitializeClient()
{
ClientSpriteRegistryCallback.event(SpriteAtlasTexture.PARTICLE_ATLAS_TEX).register(((spriteAtlasTexture, registry) ->
TorcherinoAPI.INSTANCE.getTiers().forEach((id, tier) -> {
if (!id.getNamespace().equals(MOD_ID)) { return; }
String path = id.getPath() + "_flame";
if (path.equals("normal_flame")) { path = "flame"; }
registry.register(new Identifier("torcherino", "particle/" + path));
})));
Torcherino.particles.forEach((pt) -> ParticleFactoryRegistry.getInstance().register(pt, FlameParticle.Factory::new));
// Open Torcherino Screen
ClientSidePacketRegistry.INSTANCE.register(new Identifier(MOD_ID, "ots"), (PacketContext context, PacketByteBuf buffer) ->
{
World world = MinecraftClient.getInstance().world;
BlockPos pos = buffer.readBlockPos();
Text title = buffer.readText();
int xRange = buffer.readInt();
int zRange = buffer.readInt();
int yRange = buffer.readInt();
int speed = buffer.readInt();
int redstoneMode = buffer.readInt();
context.getTaskQueue().execute(() ->
{
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof TorcherinoBlockEntity)
{
MinecraftClient.getInstance().openScreen(new TorcherinoScreen(title, xRange, zRange, yRange, speed, redstoneMode, pos,
((TierSupplier) blockEntity).getTier()));
}
});
});
// Torcherino Tier Sync
ClientSidePacketRegistry.INSTANCE.register(new Identifier(MOD_ID, "tts"), (PacketContext context, PacketByteBuf buffer) ->
{
HashMap<Identifier, Tier> tiers = new HashMap<>();
int count = buffer.readInt();
for (int i = 0; i < count; i++)
{
Identifier id = buffer.readIdentifier();
int maxSpeed = buffer.readInt();
int xzRange = buffer.readInt();
int yRange = buffer.readInt();
tiers.put(id, new Tier(maxSpeed, xzRange, yRange));
}
context.getTaskQueue().execute(() -> ((TorcherinoImpl) TorcherinoAPI.INSTANCE).setRemoteTiers(tiers));
});
}
}
21 changes: 21 additions & 0 deletions torcherino/src/main/java/torcherino/api/Tier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package torcherino.api;

public class Tier
{
private final int MAX_SPEED;
private final int XZ_RANGE;
private final int Y_RANGE;

public Tier(int maxSpeed, int xzRange, int yRange)
{
this.MAX_SPEED = maxSpeed;
this.XZ_RANGE = xzRange;
this.Y_RANGE = yRange;
}

public int getMaxSpeed() { return MAX_SPEED; }

public int getXZRange() { return XZ_RANGE; }

public int getYRange() { return Y_RANGE; }
}
8 changes: 8 additions & 0 deletions torcherino/src/main/java/torcherino/api/TierSupplier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package torcherino.api;

import net.minecraft.util.Identifier;

public interface TierSupplier
{
Identifier getTier();
}
87 changes: 87 additions & 0 deletions torcherino/src/main/java/torcherino/api/TorcherinoAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package torcherino.api;

import com.google.common.collect.ImmutableMap;
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.util.Identifier;
import torcherino.api.impl.TorcherinoImpl;

/**
* @author NinjaPhenix
* @since 1.9.51
*/
@SuppressWarnings({ "UnusedReturnValue", "unused", "SpellCheckingInspection" })
public interface TorcherinoAPI
{
/**
* The Implementation of the API, you should use this for all methods. e.g. TorcherinoAPI.INSTANCE.blacklistBlock(Blocks.STONE)
*/
TorcherinoAPI INSTANCE = TorcherinoImpl.INSTANCE;

/**
* @return Immutable map of tierID -> tier
* @since 1.9.51
*/
ImmutableMap<Identifier, Tier> getTiers();

/**
* Returns the tier for the given tierName.
*
* @param tierIdentifier The tier name to retrieve.
* @return The tier or null if it does not exist.
* @since 1.9.51
*/
Tier getTier(Identifier tierIdentifier);

/**
* @param tierIdentifier Identifier for the new tier.
* @param maxSpeed The max speed blocks of this tier should have.
* @param xzRange The max range horizontally blocks of this tier should have.
* @param yRange The max range vertically blocks of this tier should have.
* @return TRUE if the tier was registered, FALSE if tier with same name exists.
* @since 1.9.51
*/
boolean registerTier(Identifier tierIdentifier, int maxSpeed, int xzRange, int yRange);

/**
* @param blockIdentifier The Identifier of the block to be blacklisted.
* @return TRUE if added to blacklist, FALSE if already on blacklist.
* @since 1.9.51
*/
boolean blacklistBlock(Identifier blockIdentifier);

/**
* @param block The block to be blacklisted.
* @return TRUE if added to blacklist, FALSE if already on blacklist.
* @since 1.9.51
*/
boolean blacklistBlock(Block block);

/**
* @param blockEntityIdentifier The Identifier of the block entity to be blacklisted.
* @return TRUE if added to blacklist, FALSE if already on blacklist.
* @since 1.9.51
*/
boolean blacklistBlockEntity(Identifier blockEntityIdentifier);

/**
* @param blockEntityType The block entity type to be blacklisted.
* @return TRUE if added to blacklist, FALSE if already on blacklist.
* @since 1.9.51
*/
boolean blacklistBlockEntity(BlockEntityType<?> blockEntityType);

/**
* @param block The block to check is blacklisted.
* @return TRUE if blacklisted, FALSE otherwise.
* @since 1.9.51
*/
boolean isBlockBlacklisted(Block block);

/**
* @param blockEntityType The block entity type to check is blacklisted.
* @return TRUE if blacklisted, FALSE otherwise.
* @since 1.9.51
*/
boolean isBlockEntityBlacklisted(BlockEntityType<?> blockEntityType);
}
74 changes: 74 additions & 0 deletions torcherino/src/main/java/torcherino/api/TorcherinoLogic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package torcherino.api;

import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.network.ServerSidePacketRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.PacketByteBuf;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import torcherino.Torcherino;
import torcherino.api.blocks.entity.TorcherinoBlockEntity;
import torcherino.config.Config;

import java.util.Random;
import java.util.function.Consumer;

public class TorcherinoLogic
{

public static void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random)
{
if (world.isClient) { return; }
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof TorcherinoBlockEntity) { ((TorcherinoBlockEntity) blockEntity).tick(); }
}

public static ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit)
{
if (world.isClient || hand == Hand.OFF_HAND) { return ActionResult.SUCCESS; }
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof TorcherinoBlockEntity)
{
PacketByteBuf buffer = new PacketByteBuf(Unpooled.buffer());
((TorcherinoBlockEntity) blockEntity).writeClientData(buffer);
ServerSidePacketRegistry.INSTANCE.sendToPlayer(player, new Identifier(Torcherino.MOD_ID, "ots"), buffer);
}
return ActionResult.SUCCESS;
}

public static void neighborUpdate(BlockState state, World world, BlockPos pos, Block neighborBlock, BlockPos neighborPos, boolean boolean_1,
Consumer<TorcherinoBlockEntity> func)
{
if (world.isClient) { return; }
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof TorcherinoBlockEntity) { func.accept((TorcherinoBlockEntity) blockEntity); }
}

public static void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack, Block block)
{
if (world.isClient) { return; }
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof TorcherinoBlockEntity)
{
TorcherinoBlockEntity be = (TorcherinoBlockEntity) blockEntity;
if (stack.hasCustomName()) { be.setCustomName(stack.getName()); }
if (!Config.INSTANCE.online_mode.equals("")) { be.setOwner(placer == null ? "" : placer.getUuidAsString()); }
}
if (Config.INSTANCE.log_placement)
{
String prefix = placer == null ? "Something" : placer.getDisplayName().getString() + "(" + placer.getUuidAsString() + ")";
Torcherino.LOGGER.info("[Torcherino] {} placed a {} at {}, {}, {}.", prefix, Registry.BLOCK.getId(block), pos.getX(), pos.getY(), pos.getZ());
}
}
}
Loading

0 comments on commit ef60e26

Please sign in to comment.