Skip to content

Commit

Permalink
I am fucking speed bitches
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragonoidzero committed Feb 19, 2021
1 parent 1830d68 commit 5dbc58d
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 33 deletions.
4 changes: 0 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,11 @@ repositories {
}

dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.

modImplementation(include("io.github.cottonmc:LibGui:${project.libgui_version}"))
modImplementation( include("com.jamieswhiteshirt:reach-entity-attributes:${project.reach_version}"))
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ org.gradle.jvmargs=-Xmx4G
loader_version=0.11.1

# Mod Properties
mod_version = ALPHA.4
mod_version = ALPHA.5
maven_group = azzy.ttlg
archives_base_name = TTLG
libgui_version = 3.3.3+1.16.5
patchouli_version = 1.16.4-48-FABRIC-SNAPSHOT
ftl_version=0.1.4
patchouli_version = 1.16.4-50-FABRIC
ftl_version=0.2.2
reach_version = 1.0.1


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void onEntityCollision(BlockState state, World world, BlockPos pos, Entit
if(!world.isClient()) {
if(!(entity instanceof PlayerEntity && ((PlayerEntity) entity).isCreative())) {
Random random = world.getRandom();
if(entity.isLiving() && random.nextInt(51) == 0) {
if(random.nextInt(51) == 0) {
if(random.nextBoolean()) {
((LivingEntity) entity).applyStatusEffect(new StatusEffectInstance(StatusEffects.LEVITATION, 10 + random.nextInt(20), 39, false, false, false));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void onEntityCollision(BlockState state, World world, BlockPos pos, Entit
if(!world.isClient()) {
if(!(entity instanceof PlayerEntity && ((PlayerEntity) entity).isCreative())) {
Random random = world.getRandom();
if(entity.isLiving() && random.nextInt(101) == 0) {
if(random.nextInt(101) == 0) {
if(random.nextBoolean()) {
((LivingEntity) entity).applyStatusEffect(new StatusEffectInstance(StatusEffects.LEVITATION, 10 + random.nextInt(20), 39, false, false, false));
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/azzy/fabric/lookingglass/block/TTLGBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.DyeColor;
import net.minecraft.util.Identifier;
import net.minecraft.util.Rarity;
import net.minecraft.util.registry.Registry;
Expand Down Expand Up @@ -96,6 +97,7 @@ private static FabricBlockSettings eldenMachine() {
public static final Block WHITESTONE_TILE = registerGeneratedBlock("whitestone_tile", new Block(FabricBlockSettings.copyOf(WHITESTONE_BLOCK)), null, null, basicMachineItem(), SingletType.BLOCK);
public static final Block[] WHITESTONE_BRICK_SET = registerBuildingBlocks("whitestone_bricks", FabricBlockSettings.copyOf(WHITESTONE_BLOCK), basicMachineItem(), WHISTONE_POLISHED[0].asItem(), false);
public static final Block[] WHITESTONE_LARGE_BRICK_SET = registerBuildingBlocks("large_whitestone_bricks", FabricBlockSettings.copyOf(WHITESTONE_BLOCK), basicMachineItem(), WHITESTONE_TILE.asItem(), false);
public static final Block DWARVEN_STONE = registerGeneratedBlock("dwarven_stone", new Block(FabricBlockSettings.copyOf(Blocks.STONE).resistance(500).materialColor(DyeColor.GRAY).sounds(BlockSoundGroup.NETHER_BRICKS)), null, null, basicMachineItem(), SingletType.BLOCK);
public static final Block[] BASALT_BRICK_SET = registerBuildingBlocks("basalt_bricks", FabricBlockSettings.copyOf(Blocks.POLISHED_BASALT), basicMachineItem(), Items.POLISHED_BASALT, false);
public static final Block HERRINGBONE_OAK_PLANKS = registerBlock("herringbone_oak_planks", new HerringboneWoodBlock(FabricBlockSettings.copyOf(Blocks.OAK_PLANKS)), basicMachineItem());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import dev.technici4n.fasttransferlib.api.fluid.FluidApi;
import dev.technici4n.fasttransferlib.api.fluid.FluidIo;
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
import net.fabricmc.fabric.api.provider.v1.block.BlockApiLookup;
import net.fabricmc.fabric.api.lookup.v1.block.BlockApiLookup;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
Expand All @@ -18,14 +18,16 @@

public abstract class BasePipeEntity<T> extends BlockEntity implements Tickable, BlockEntityClientSerializable, RedstoneReactiveEntity {

private final BlockApiLookup<T, Direction> lookup;
private final boolean strict;
protected final int offset = LookingGlassCommon.RANDOM.nextInt(10);
protected boolean straight = false;
protected final Set<Direction> IO = new HashSet<>();
private final BlockApiLookup<T, Direction> lookup;

public BasePipeEntity(BlockEntityType<?> type, BlockApiLookup<T, Direction> lookup) {
public BasePipeEntity(BlockEntityType<?> type, BlockApiLookup<T, Direction> lookup, boolean strict) {
super(type);
this.lookup = lookup;
this.strict = strict;
}

@Override
Expand All @@ -44,18 +46,39 @@ public void tick() {
public Set<T> checkConnections() {
Set<T> ioSet = new HashSet<>();
for(Direction direction : Direction.values()){
T io = lookup.get(world, pos.offset(direction), direction.getOpposite());
if(io != null){
if(!getCachedState().get(PipeBlock.getFACING().get(direction))) {
world.setBlockState(pos, world.getBlockState(pos).with(PipeBlock.getFACING().get(direction), true));
IO.add(direction);
BlockEntity entity = world.getBlockEntity(pos.offset(direction));
if(entity instanceof BasePipeEntity && strict) {
if(entity != null) {
BlockEntityType<?> type = entity.getType();
if (type == getType()) {
T io = lookup.get(world, pos.offset(direction), direction.getOpposite());
if (io != null) {
if (!getCachedState().get(PipeBlock.getFACING().get(direction))) {
world.setBlockState(pos, world.getBlockState(pos).with(PipeBlock.getFACING().get(direction), true));
IO.add(direction);
}
ioSet.add(io);
continue;
}
}
}
ioSet.add(io);
}
else {
world.setBlockState(pos, world.getBlockState(pos).with(PipeBlock.getFACING().get(direction), false));
getIO().remove(direction);
}
else {
T io = lookup.get(world, pos.offset(direction), direction.getOpposite());
if(io != null){
if(!getCachedState().get(PipeBlock.getFACING().get(direction))) {
world.setBlockState(pos, world.getBlockState(pos).with(PipeBlock.getFACING().get(direction), true));
IO.add(direction);
}
ioSet.add(io);
}
else {
world.setBlockState(pos, world.getBlockState(pos).with(PipeBlock.getFACING().get(direction), false));
getIO().remove(direction);
}
}
}
return ioSet;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,18 @@ public class PowerPipeEntity extends BasePipeEntity<EnergyIo> implements EnergyI

private final double maxPower, transferRate;
private double power;
private boolean ticked;

public PowerPipeEntity(BlockEntityType type, double transferRate) {
super(type, EnergyApi.SIDED);
super(type, EnergyApi.SIDED, true);
this.maxPower = transferRate * 4.0;
this.transferRate = transferRate;
}

@Override
public void performTransfers(Set<EnergyIo> participants) {
List<PowerPipeEntity> cables = new ArrayList<>();
cables.add(this);
for (EnergyIo energyIo : participants.toArray(new EnergyIo[0])) {
if(energyIo instanceof PowerPipeEntity) {
if(((PowerPipeEntity) energyIo).getType() == getType()) {
cables.add((PowerPipeEntity) energyIo);
}
continue;
}
if(power > 0 && energyIo.supportsInsertion()) {
Expand All @@ -50,7 +46,13 @@ else if (energyIo.getEnergy() > 0 && energyIo.supportsExtraction()) {
}
}

//Taken from Techreborn's CableBlockEntity
//Taken from Techreborn's CableBlockEntity, some of it at least

List<PowerPipeEntity> cables = new ArrayList<>();

if(!ticked) {
cables.addAll(getNeighbours());
}

if(cables.size() > 1) {
double totalPower = cables.stream().mapToDouble(EnergyIo::getEnergy).sum();
Expand All @@ -63,6 +65,8 @@ else if (energyIo.getEnergy() > 0 && energyIo.supportsExtraction()) {
if(!world.isClient()) {
sync();
}

ticked = false;
}

public Set<PowerPipeEntity> getNeighbours() {
Expand All @@ -78,9 +82,10 @@ public Set<PowerPipeEntity> getNeighbours() {

public void getNeighbours(Set<PowerPipeEntity> neighbours) {
neighbours.add(this);
this.ticked = true;
Arrays.stream(Direction.values())
.map(direction -> world.getBlockEntity(pos.offset(direction)))
.filter(blockEntity -> blockEntity.getType() == getType())
.filter(blockEntity -> blockEntity != null && blockEntity.getType() == getType())
.forEach(entity -> {
if(!neighbours.contains(entity))
((PowerPipeEntity)entity).getNeighbours(neighbours);
Expand Down Expand Up @@ -147,7 +152,7 @@ public CompoundTag toTag(CompoundTag tag) {

@Override
public void fromTag(BlockState state, CompoundTag tag) {
power = tag.getDouble("energy");
power = tag.getDouble("power");
super.fromTag(state, tag);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class EnergyProbeItem extends Item {

public EnergyProbeItem(Settings settings) {
Expand All @@ -20,8 +23,10 @@ public ActionResult useOnBlock(ItemUsageContext context) {
World world = context.getWorld();
EnergyIo io = EnergyApi.SIDED.get(world, context.getBlockPos(), context.getSide());
if(io != null) {
if(!world.isClient())
context.getPlayer().sendMessage(new LiteralText(io.getEnergy() + "Lu"), true);
if(!world.isClient()) {
double energy = io.getEnergy();
context.getPlayer().sendMessage(new LiteralText((Double.isFinite(energy) ? Math.ceil(energy) : energy) + " Lu"), true);
}
return ActionResult.SUCCESS;
}
return super.useOnBlock(context);
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/azzy/fabric/lookingglass/item/TTLGItems.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package azzy.fabric.lookingglass.item;

import azzy.fabric.lookingglass.util.datagen.ModelJsonGen;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
Expand Down Expand Up @@ -38,12 +39,20 @@ private static FabricItemSettings eldenmetalSettings() {
public static final Item PRISMATIC_SHIMMERFIN = registerItem("shimmerfin", new FishWeaponItem(true, 199, defaultSettings().rarity(Rarity.EPIC).fireproof().food(shimmerfin)));

//Materials
public static final Item FISH_FEED = registerItem("fish_feed", new Item(defaultSettings().food(badNoms)));
public static final Item DWARVEN_CLAY = registerGeneratedItem("dwarven_clay", new Item(defaultSettings()));
public static final Item ELDENMETAL_NUGGET = registerItem("eldenmetal_drop", new Item(eldenmetalSettings()));
public static final Item ELDENMETAL_INGOT = registerItem("eldenmetal_tear", new Item(eldenmetalSettings()));
public static final Item ELDENMETAL_GEMSTONE = registerItem("eldenmetal_gem", new Item(eldenmetalSettings()));
public static final Item FISH_FEED = registerItem("fish_feed", new Item(defaultSettings().food(badNoms)));

private static Item registerItem(String name, Item item) {
return Registry.register(Registry.ITEM, new Identifier(MODID, name), item);
}

private static Item registerGeneratedItem(String name, Item item) {
Identifier id = new Identifier(MODID, name);
if(REGEN_ITEMS)
ModelJsonGen.genItemJson(METADATA, id);
return Registry.register(Registry.ITEM, id, item);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@

public class ModelJsonGen {

public static void genItemJson(Metadata metadata, Identifier name) {
String item = "{\n" +
" \"parent\": \"item/generated\",\n" +
" \"textures\": {\n" +
" \"layer0\": \"" + name.getNamespace() + ":item/" + name.getPath() + "\"\n" +
" }\n" +
"}";

try {
FileUtils.writeStringToFile(metadata.genResourceJson(name.getPath(), "", Metadata.ResourceType.ITEM_MODEL), item, Charsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
}
}

public static void genBlockJson(Metadata metadata, Identifier texId, Identifier name, String path) {
String block = "{\n" +
" \"parent\": \"minecraft:block/cube_all\",\n" +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "lookingglass:block/dwarven_stone"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "lookingglass:block/dwarven_stone"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "lookingglass:item/dwarven_clay"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "lookingglass:block/dwarven_stone"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"type": "minecraft:block",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:item",
"name": "lookingglass:dwarven_stone"
}
],
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
]
}
]
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": "lookingglass",
"version": "2.0.0-alpha.4",

"name": "Through the Looking Glass",
"name": "Through The Looking Glass",
"description": "Not a mod about glass working",
"authors": [
"Azazelthedemonlord"
Expand Down

0 comments on commit 5dbc58d

Please sign in to comment.