mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-19 03:39:17 +00:00
- Added 1.6.4 port
- Fixed /mt name command - Renames MC17 to MC172, in preparation of the 1.7.10 port
This commit is contained in:
1 parent
0c535134c5
commit
db900d3b60
126 files changed
+4880
-57
No files matched your search
@@ -4,3 +4,4 @@ build
|
||||
run
|
||||
/MineTweaker3-Web/nbproject/private/
|
||||
/MineTweaker3-Web/doc
|
||||
/MineTweaker3-MC164-Main/eclipse
|
||||
@@ -0,0 +1,395 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.EventList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class AbstractEventManager implements IEventManager {
|
||||
// ##########################
|
||||
// ### PlayerCraftedEvent ###
|
||||
// ##########################
|
||||
|
||||
private final EventList<PlayerCraftedEvent> elPlayerCrafted = new EventList<PlayerCraftedEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerCrafted(IPlayerCraftedEventHandler ev) {
|
||||
return elPlayerCrafted.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerCrafted() {
|
||||
return elPlayerCrafted.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerCrafted(PlayerCraftedEvent event) {
|
||||
elPlayerCrafted.publish(event);
|
||||
}
|
||||
|
||||
// ##########################
|
||||
// ### PlayerSmeltedEvent ###
|
||||
// ##########################
|
||||
|
||||
private final EventList<PlayerSmeltedEvent> elPlayerSmelted = new EventList<PlayerSmeltedEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerSmelted(IPlayerSmeltedEventHandler ev) {
|
||||
return elPlayerSmelted.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerSmelted() {
|
||||
return elPlayerSmelted.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerSmelted(PlayerSmeltedEvent event) {
|
||||
elPlayerSmelted.publish(event);
|
||||
}
|
||||
|
||||
// ###################################
|
||||
// ### PlayerChangedDimensionEvent ###
|
||||
// ###################################
|
||||
|
||||
private final EventList<PlayerChangedDimensionEvent> elPlayerChangedDimension = new EventList<PlayerChangedDimensionEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerChangedDimension(IPlayerChangedDimensionEventHandler ev) {
|
||||
return elPlayerChangedDimension.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerChangedDimension() {
|
||||
return elPlayerChangedDimension.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerChangedDimension(PlayerChangedDimensionEvent event) {
|
||||
elPlayerChangedDimension.publish(event);
|
||||
}
|
||||
|
||||
// ###########################
|
||||
// ### PlayerLoggedInEvent ###
|
||||
// ###########################
|
||||
|
||||
private final EventList<PlayerLoggedInEvent> elPlayerLoggedIn = new EventList<PlayerLoggedInEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerLoggedIn(IPlayerLoggedInEventHandler ev) {
|
||||
return elPlayerLoggedIn.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerLoggedIn() {
|
||||
return elPlayerLoggedIn.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerLoggedIn(PlayerLoggedInEvent event) {
|
||||
elPlayerLoggedIn.publish(event);
|
||||
}
|
||||
|
||||
// ############################
|
||||
// ### PlayerLoggedOutEvent ###
|
||||
// ############################
|
||||
|
||||
private final EventList<PlayerLoggedOutEvent> elPlayerLoggedOut = new EventList<PlayerLoggedOutEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerLoggedOut(IPlayerLoggedOutEventHandler ev) {
|
||||
return elPlayerLoggedOut.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerLoggedOut() {
|
||||
return elPlayerLoggedOut.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerLoggedOut(PlayerLoggedOutEvent event) {
|
||||
elPlayerLoggedOut.publish(event);
|
||||
}
|
||||
|
||||
// ##########################
|
||||
// ### PlayerRespawnEvent ###
|
||||
// ##########################
|
||||
|
||||
private final EventList<PlayerRespawnEvent> elPlayerRespawn = new EventList<PlayerRespawnEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerRespawn(IPlayerRespawnEventHandler ev) {
|
||||
return elPlayerRespawn.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerRespawn() {
|
||||
return elPlayerRespawn.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerRespawn(PlayerRespawnEvent event) {
|
||||
elPlayerRespawn.publish(event);
|
||||
}
|
||||
|
||||
// ###############################
|
||||
// ### PlayerAttackEntityEvent ###
|
||||
// ###############################
|
||||
|
||||
private final EventList<PlayerAttackEntityEvent> elPlayerAttackEntity = new EventList<PlayerAttackEntityEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerAttackEntity(IPlayerAttackEntityEventHandler ev) {
|
||||
return elPlayerAttackEntity.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerAttackEntity() {
|
||||
return elPlayerAttackEntity.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerAttackEntity(PlayerAttackEntityEvent event) {
|
||||
elPlayerAttackEntity.publish(event);
|
||||
}
|
||||
|
||||
// ###########################
|
||||
// ### PlayerBonemealEvent ###
|
||||
// ###########################
|
||||
|
||||
private final EventList<PlayerBonemealEvent> elPlayerBonemeal = new EventList<PlayerBonemealEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerBonemeal(IPlayerBonemealEventHandler ev) {
|
||||
return elPlayerBonemeal.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerBonemeal() {
|
||||
return elPlayerBonemeal.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerBonemeal(PlayerBonemealEvent event) {
|
||||
elPlayerBonemeal.publish(event);
|
||||
}
|
||||
|
||||
// #################################
|
||||
// ### PlayerInteractEntityEvent ###
|
||||
// #################################
|
||||
|
||||
private final EventList<PlayerInteractEntityEvent> elPlayerInteractEntity = new EventList<PlayerInteractEntityEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerInteractEntity(IPlayerInteractEntityEventHandler ev) {
|
||||
return elPlayerInteractEntity.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerInteractEntity() {
|
||||
return elPlayerInteractEntity.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
elPlayerInteractEntity.publish(event);
|
||||
}
|
||||
|
||||
// #########################
|
||||
// ### PlayerPickupEvent ###
|
||||
// #########################
|
||||
|
||||
private final EventList<PlayerPickupEvent> elPlayerPickup = new EventList<PlayerPickupEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerPickup(IPlayerPickupEventHandler ev) {
|
||||
return elPlayerPickup.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerPickup() {
|
||||
return elPlayerPickup.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerPickup(PlayerPickupEvent event) {
|
||||
elPlayerPickup.publish(event);
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### PlayerPickupItemEvent ###
|
||||
// #############################
|
||||
|
||||
private final EventList<PlayerPickupItemEvent> elPlayerPickupItem = new EventList<PlayerPickupItemEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerPickupItem(IPlayerPickupItemEventHandler ev) {
|
||||
return elPlayerPickupItem.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerPickupItem() {
|
||||
return elPlayerPickupItem.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||
elPlayerPickupItem.publish(event);
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### PlayerFillBucketEvent ###
|
||||
// #############################
|
||||
|
||||
private final EventList<PlayerFillBucketEvent> elPlayerFillBucket = new EventList<PlayerFillBucketEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerFillBucket(IPlayerFillBucketEventHandler ev) {
|
||||
return elPlayerFillBucket.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerFillBucket() {
|
||||
return elPlayerFillBucket.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerFillBucket(PlayerFillBucketEvent event) {
|
||||
elPlayerFillBucket.publish(event);
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### PlayerDeathDropsEvent ###
|
||||
// #############################
|
||||
|
||||
private final EventList<PlayerDeathDropsEvent> elPlayerDeathDrops = new EventList<PlayerDeathDropsEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerDeathDrops(IPlayerDeathDropsEventHandler ev) {
|
||||
return elPlayerDeathDrops.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerDeathDrops() {
|
||||
return elPlayerDeathDrops.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerDeathDrops(PlayerDeathDropsEvent event) {
|
||||
elPlayerDeathDrops.publish(event);
|
||||
}
|
||||
|
||||
// ###########################
|
||||
// ### PlayerInteractEvent ###
|
||||
// ###########################
|
||||
|
||||
private final EventList<PlayerInteractEvent> elPlayerInteract = new EventList<PlayerInteractEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerInteract(IPlayerInteractEventHandler ev) {
|
||||
return elPlayerInteract.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerInteract() {
|
||||
return elPlayerInteract.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerInteract(PlayerInteractEvent event) {
|
||||
elPlayerInteract.publish(event);
|
||||
}
|
||||
|
||||
// ################################
|
||||
// ### PlayerOpenContainerEvent ###
|
||||
// ################################
|
||||
|
||||
private final EventList<PlayerOpenContainerEvent> elPlayerOpenContainer = new EventList<PlayerOpenContainerEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerOpenContainer(IPlayerOpenContainerEventHandler ev) {
|
||||
return elPlayerOpenContainer.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerOpenContainer() {
|
||||
return elPlayerOpenContainer.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerOpenContainer(PlayerOpenContainerEvent event) {
|
||||
elPlayerOpenContainer.publish(event);
|
||||
}
|
||||
|
||||
// ###########################
|
||||
// ### PlayerPickupXpEvent ###
|
||||
// ###########################
|
||||
|
||||
private final EventList<PlayerPickupXpEvent> elPlayerPickupXp = new EventList<PlayerPickupXpEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerPickupXp(IPlayerPickupXpEventHandler ev) {
|
||||
return elPlayerPickupXp.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerPickupXp() {
|
||||
return elPlayerPickupXp.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerPickup(PlayerPickupXpEvent event) {
|
||||
elPlayerPickupXp.publish(event);
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### PlayerSleepInBedEvent ###
|
||||
// #############################
|
||||
|
||||
private final EventList<PlayerSleepInBedEvent> elPlayerSleepInBed = new EventList<PlayerSleepInBedEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerSleepInBed(IPlayerSleepInBedEventHandler ev) {
|
||||
return elPlayerSleepInBed.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerSleepInBed() {
|
||||
return elPlayerSleepInBed.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerSleepInBed(PlayerSleepInBedEvent event) {
|
||||
elPlayerSleepInBed.publish(event);
|
||||
}
|
||||
|
||||
// #########################
|
||||
// ### PlayerUseHoeEvent ###
|
||||
// #########################
|
||||
|
||||
private final EventList<PlayerUseHoeEvent> elPlayerUseHoe = new EventList<PlayerUseHoeEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerUseHoe(IPlayerUseHoeEventHandler ev) {
|
||||
return elPlayerUseHoe.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerUseHoe() {
|
||||
return elPlayerUseHoe.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerUseHoe(PlayerUseHoeEvent event) {
|
||||
elPlayerUseHoe.publish(event);
|
||||
}
|
||||
|
||||
// ###############################
|
||||
// ### PlayerUseItemStartEvent ###
|
||||
// ###############################
|
||||
|
||||
private final EventList<PlayerUseItemStartEvent> elPlayerUseItemStart = new EventList<PlayerUseItemStartEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerUseItemStart(IPlayerUseItemStartEventHandler ev) {
|
||||
return elPlayerUseItemStart.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerUseItemStart() {
|
||||
return elPlayerUseItemStart.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerUseItemStart(PlayerUseItemStartEvent event) {
|
||||
elPlayerUseItemStart.publish(event);
|
||||
}
|
||||
|
||||
// ##############################
|
||||
// ### PlayerUseItemTickEvent ###
|
||||
// ##############################
|
||||
|
||||
private final EventList<PlayerUseItemTickEvent> elPlayerUseItemTick = new EventList<PlayerUseItemTickEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerUseItemTick(IPlayerUseItemTickEventHandler ev) {
|
||||
return elPlayerUseItemTick.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerUseItemTick() {
|
||||
return elPlayerUseItemTick.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerUseItemTick(PlayerUseItemTickEvent event) {
|
||||
elPlayerUseItemTick.publish(event);
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public interface IEventManager {
|
||||
|
||||
public IEventHandle onPlayerPickupXp(IPlayerPickupXpEventHandler ev);
|
||||
|
||||
/*public IEventHandle onPlayerSleepInBed(IPlayerSleepInBedEventHandler ev);
|
||||
public IEventHandle onPlayerSleepInBed(IPlayerSleepInBedEventHandler ev);
|
||||
|
||||
public IEventHandle onPlayerUseHoe(IPlayerUseHoeEventHandler ev);
|
||||
|
||||
@@ -52,7 +52,7 @@ public interface IEventManager {
|
||||
|
||||
public IEventHandle onPlayerUseItemTick(IPlayerUseItemTickEventHandler ev);
|
||||
|
||||
public IEventHandle onPlayerUseItemStop(IPlayerUseItemStopEventHandler ev);
|
||||
/*public IEventHandle onPlayerUseItemStop(IPlayerUseItemStopEventHandler ev);
|
||||
|
||||
public IEventHandle onPlayerUseItemFinish(IPlayerUserItemFinishEventHandler ev);
|
||||
|
||||
|
||||
+3
-1
@@ -6,6 +6,7 @@
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.IEventHandler;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
@@ -13,6 +14,7 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.IPlayerAttackEntityEventHandler")
|
||||
public interface IPlayerAttackEntityEventHandler {
|
||||
public interface IPlayerAttackEntityEventHandler extends IEventHandler<PlayerAttackEntityEvent> {
|
||||
@Override
|
||||
public void handle(PlayerAttackEntityEvent event);
|
||||
}
|
||||
+3
-1
@@ -6,6 +6,7 @@
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.IEventHandler;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
@@ -13,6 +14,7 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.IPlayerBonemealEventHandler")
|
||||
public interface IPlayerBonemealEventHandler {
|
||||
public interface IPlayerBonemealEventHandler extends IEventHandler<PlayerBonemealEvent> {
|
||||
@Override
|
||||
public void handle(PlayerBonemealEvent event);
|
||||
}
|
||||
+6
-1
@@ -6,10 +6,15 @@
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.IEventHandler;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public interface IPlayerChangedDimensionEventHandler {
|
||||
@ZenClass("minetweaker.event.IPlayerChangedDimensionEventHandler")
|
||||
public interface IPlayerChangedDimensionEventHandler extends IEventHandler<PlayerChangedDimensionEvent> {
|
||||
@Override
|
||||
public void handle(PlayerChangedDimensionEvent event);
|
||||
}
|
||||
+3
-1
@@ -6,6 +6,7 @@
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.IEventHandler;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
@@ -13,6 +14,7 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.IPlayerCraftedEventHandler")
|
||||
public interface IPlayerCraftedEventHandler {
|
||||
public interface IPlayerCraftedEventHandler extends IEventHandler<PlayerCraftedEvent> {
|
||||
@Override
|
||||
public void handle(PlayerCraftedEvent ev);
|
||||
}
|
||||
+3
-1
@@ -6,6 +6,7 @@
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.IEventHandler;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
@@ -13,6 +14,7 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.IPlayerDeathDropsEventHandler")
|
||||
public interface IPlayerDeathDropsEventHandler {
|
||||
public interface IPlayerDeathDropsEventHandler extends IEventHandler<PlayerDeathDropsEvent> {
|
||||
@Override
|
||||
public void handle(PlayerDeathDropsEvent event);
|
||||
}
|
||||
+3
-1
@@ -6,6 +6,7 @@
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.IEventHandler;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
@@ -13,6 +14,7 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.IPlayerFillBucketEventHandler")
|
||||
public interface IPlayerFillBucketEventHandler {
|
||||
public interface IPlayerFillBucketEventHandler extends IEventHandler<PlayerFillBucketEvent> {
|
||||
@Override
|
||||
public void handle(PlayerFillBucketEvent event);
|
||||
}
|
||||
+3
-1
@@ -6,6 +6,7 @@
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.IEventHandler;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
@@ -13,6 +14,7 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.IPlayerInteractEntityEventHandler")
|
||||
public interface IPlayerInteractEntityEventHandler {
|
||||
public interface IPlayerInteractEntityEventHandler extends IEventHandler<PlayerInteractEntityEvent> {
|
||||
@Override
|
||||
public void handle(PlayerInteractEntityEvent event);
|
||||
}
|
||||
+3
-1
@@ -6,6 +6,7 @@
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.IEventHandler;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
@@ -13,6 +14,7 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.IPlayerInteractEventHandler")
|
||||
public interface IPlayerInteractEventHandler {
|
||||
public interface IPlayerInteractEventHandler extends IEventHandler<PlayerInteractEvent> {
|
||||
@Override
|
||||
public void handle(PlayerInteractEvent event);
|
||||
}
|
||||
+6
-1
@@ -6,10 +6,15 @@
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.IEventHandler;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public interface IPlayerLoggedInEventHandler {
|
||||
@ZenClass("minetweaker.event.IPlayerLoggedInEventHandler")
|
||||
public interface IPlayerLoggedInEventHandler extends IEventHandler<PlayerLoggedInEvent> {
|
||||
@Override
|
||||
public void handle(PlayerLoggedInEvent event);
|
||||
}
|
||||
+3
-1
@@ -6,6 +6,7 @@
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.IEventHandler;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
@@ -13,6 +14,7 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.IPlayerLoggedOutEventHandler")
|
||||
public interface IPlayerLoggedOutEventHandler {
|
||||
public interface IPlayerLoggedOutEventHandler extends IEventHandler<PlayerLoggedOutEvent> {
|
||||
@Override
|
||||
public void handle(PlayerLoggedOutEvent event);
|
||||
}
|
||||
+3
-1
@@ -6,6 +6,7 @@
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.IEventHandler;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
@@ -13,6 +14,7 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.IPlayerOpenContainerEventHandler")
|
||||
public interface IPlayerOpenContainerEventHandler {
|
||||
public interface IPlayerOpenContainerEventHandler extends IEventHandler<PlayerOpenContainerEvent> {
|
||||
@Override
|
||||
public void handle(PlayerOpenContainerEvent event);
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.IEventHandler;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
@@ -13,6 +14,7 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.IPlayerPickupEventHandler")
|
||||
public interface IPlayerPickupEventHandler {
|
||||
public interface IPlayerPickupEventHandler extends IEventHandler<PlayerPickupEvent> {
|
||||
@Override
|
||||
public void handle(PlayerPickupEvent event);
|
||||
}
|
||||
+3
-1
@@ -6,6 +6,7 @@
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.IEventHandler;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
@@ -13,6 +14,7 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.IPlayerPickupItemEventHandler")
|
||||
public interface IPlayerPickupItemEventHandler {
|
||||
public interface IPlayerPickupItemEventHandler extends IEventHandler<PlayerPickupItemEvent> {
|
||||
@Override
|
||||
public void handle(PlayerPickupItemEvent event);
|
||||
}
|
||||
+3
-1
@@ -6,6 +6,7 @@
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.IEventHandler;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
@@ -13,6 +14,7 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.IPlayerPickupXpEventHandler")
|
||||
public interface IPlayerPickupXpEventHandler {
|
||||
public interface IPlayerPickupXpEventHandler extends IEventHandler<PlayerPickupXpEvent> {
|
||||
@Override
|
||||
public void handle(PlayerPickupXpEvent event);
|
||||
}
|
||||
+3
-1
@@ -6,6 +6,7 @@
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.IEventHandler;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
@@ -13,6 +14,7 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.IPlayerRespawnEventHandler")
|
||||
public interface IPlayerRespawnEventHandler {
|
||||
public interface IPlayerRespawnEventHandler extends IEventHandler<PlayerRespawnEvent> {
|
||||
@Override
|
||||
public void handle(PlayerRespawnEvent event);
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.IEventHandler;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.IPlayerSleepInBedEventHandler")
|
||||
public interface IPlayerSleepInBedEventHandler extends IEventHandler<PlayerSleepInBedEvent> {
|
||||
@Override
|
||||
public void handle(PlayerSleepInBedEvent event);
|
||||
}
|
||||
+3
-1
@@ -6,6 +6,7 @@
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.IEventHandler;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
@@ -13,6 +14,7 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.IPlayerSmeltedEventHandler")
|
||||
public interface IPlayerSmeltedEventHandler {
|
||||
public interface IPlayerSmeltedEventHandler extends IEventHandler<PlayerSmeltedEvent> {
|
||||
@Override
|
||||
public void handle(PlayerSmeltedEvent event);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.IEventHandler;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.IPlayerUseHoeEventHandler")
|
||||
public interface IPlayerUseHoeEventHandler extends IEventHandler<PlayerUseHoeEvent> {
|
||||
@Override
|
||||
public void handle(PlayerUseHoeEvent event);
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.IEventHandler;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.IPlayerUseItemStartEventHandler")
|
||||
public interface IPlayerUseItemStartEventHandler extends IEventHandler<PlayerUseItemStartEvent> {
|
||||
@Override
|
||||
public void handle(PlayerUseItemStartEvent event);
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.IEventHandler;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.IPlayerUseItemTickEventHandler")
|
||||
public interface IPlayerUseItemTickEventHandler extends IEventHandler<PlayerUseItemTickEvent> {
|
||||
@Override
|
||||
public void handle(PlayerUseItemTickEvent event);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerSleepInBedEvent")
|
||||
public class PlayerSleepInBedEvent {
|
||||
private final IPlayer player;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
|
||||
public PlayerSleepInBedEvent(IPlayer player, int x, int y, int z) {
|
||||
this.player = player;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("x")
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@ZenGetter("y")
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@ZenGetter("z")
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.IBlockGroup;
|
||||
import minetweaker.api.world.IDimension;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerUseHoeEvent")
|
||||
public class PlayerUseHoeEvent {
|
||||
private final IPlayer player;
|
||||
private final IItemStack item;
|
||||
private final IBlockGroup blocks;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private boolean canceled;
|
||||
private boolean processed;
|
||||
|
||||
public PlayerUseHoeEvent(IPlayer player, IItemStack item, IBlockGroup blocks, int x, int y, int z) {
|
||||
this.player = player;
|
||||
this.item = item;
|
||||
this.blocks = blocks;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
canceled = false;
|
||||
processed = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void process() {
|
||||
processed = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("processed")
|
||||
public boolean isProcessed() {
|
||||
return processed;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("item")
|
||||
public IItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
@ZenGetter("blocks")
|
||||
public IBlockGroup getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@ZenGetter("x")
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@ZenGetter("y")
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@ZenGetter("z")
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@ZenGetter("dimension")
|
||||
public IDimension getDimension() {
|
||||
return blocks.getDimension();
|
||||
}
|
||||
|
||||
@ZenGetter("block")
|
||||
public IBlock getBlock() {
|
||||
return blocks.getBlock(x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerUseItemStartEvent")
|
||||
public class PlayerUseItemStartEvent {
|
||||
private final IPlayer player;
|
||||
private final IItemStack item;
|
||||
private boolean canceled;
|
||||
|
||||
public PlayerUseItemStartEvent(IPlayer player, IItemStack item) {
|
||||
this.player = player;
|
||||
this.item = item;
|
||||
|
||||
canceled = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("item")
|
||||
public IItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerUseItemTickEvent")
|
||||
public class PlayerUseItemTickEvent {
|
||||
private final IPlayer player;
|
||||
private final IItemStack item;
|
||||
private final int duration;
|
||||
private boolean canceled;
|
||||
|
||||
public PlayerUseItemTickEvent(IPlayer player, IItemStack item, int duration) {
|
||||
this.player = player;
|
||||
this.item = item;
|
||||
this.duration = duration;
|
||||
|
||||
canceled = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("item")
|
||||
public IItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
@ZenGetter("duration")
|
||||
public int getDuration() {
|
||||
return duration;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.util;
|
||||
|
||||
import minetweaker.api.event.IEventHandle;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class EventList<T> {
|
||||
private EventNode first = null;
|
||||
private EventNode last = null;
|
||||
|
||||
public IEventHandle add(IEventHandler<T> handler) {
|
||||
EventNode node = new EventNode(handler, last, null);
|
||||
|
||||
synchronized(this) {
|
||||
if (first == null) {
|
||||
first = node;
|
||||
}
|
||||
if (last != null) {
|
||||
last.next = node;
|
||||
}
|
||||
last = node;
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
public boolean hasHandlers() {
|
||||
return first != null;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return first == null;
|
||||
}
|
||||
|
||||
public void publish(T event) {
|
||||
EventNode current = null;
|
||||
|
||||
synchronized(this) {
|
||||
current = first;
|
||||
}
|
||||
|
||||
while (current != null) {
|
||||
current.handler.handle(event);
|
||||
|
||||
synchronized(this) {
|
||||
current = current.next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class EventNode implements IEventHandle {
|
||||
private final IEventHandler<T> handler;
|
||||
private EventNode next;
|
||||
private EventNode prev;
|
||||
|
||||
public EventNode(IEventHandler<T> handler, EventNode prev, EventNode next) {
|
||||
this.handler = handler;
|
||||
this.prev = prev;
|
||||
this.next = next;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
synchronized (EventList.this) {
|
||||
if (prev == null) {
|
||||
first = next;
|
||||
} else {
|
||||
prev.next = next;
|
||||
}
|
||||
|
||||
if (next == null) {
|
||||
last = prev;
|
||||
} else {
|
||||
next.prev = prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.util;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public interface IEventHandler<T> {
|
||||
public void handle(T event);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import minetweaker.tasks.RegisterZenClassesTask;
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
name = "forge"
|
||||
url = "http://files.minecraftforge.net/maven"
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath 'net.minecraftforge.gradle:ForgeGradle:1.0-SNAPSHOT'
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'forge'
|
||||
|
||||
version = "1.6.4-3.0.0"
|
||||
//group= "com.yourname.modid" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
archivesBaseName = project.projectDir.name
|
||||
|
||||
dependencies {
|
||||
dependencies {
|
||||
compile project(':ZenScript')
|
||||
compile project(':MineTweaker3-API')
|
||||
}
|
||||
}
|
||||
|
||||
task makeRegistry(type: RegisterZenClassesTask) {
|
||||
inputDir = file('build/classes/main')
|
||||
outputDir = file('build/classes/main')
|
||||
className = 'minetweaker.mc164.MineTweakerRegistry'
|
||||
}
|
||||
|
||||
tasks.jar.dependsOn(makeRegistry)
|
||||
|
||||
minecraft {
|
||||
version = "1.6.4-9.11.1.964"
|
||||
}
|
||||
|
||||
processResources
|
||||
{
|
||||
// replace stuff in mcmod.info, nothing else
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include 'mcmod.info'
|
||||
|
||||
// replace version and mcversion
|
||||
expand 'version':project.version, 'mcversion':project.minecraft.version
|
||||
}
|
||||
|
||||
// copy everything else, thats not the mcmod.info
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
exclude 'mcmod.info'
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,6 @@
|
||||
#Tue Oct 29 18:00:54 CDT 2013
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip
|
||||
@@ -0,0 +1,394 @@
|
||||
package minetweaker.mc164;
|
||||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.mc164.item.MCItemStack;
|
||||
|
||||
import net.minecraft.command.ICommand;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import stanhebben.zenscript.util.StringUtil;
|
||||
|
||||
/**
|
||||
* Implements the /minetweaker command set.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class MineTweakerCommand implements ICommand {
|
||||
// ###########################
|
||||
// ## Public static methods ##
|
||||
// ###########################
|
||||
|
||||
public static void sendChatMessage(ICommandSender sender, String message) {
|
||||
sender.sendChatToPlayer(ChatMessageComponent.createFromText(message));
|
||||
}
|
||||
|
||||
private static final List<String> aliases = Arrays.asList("mt");
|
||||
|
||||
// #######################################
|
||||
// ## ICommand interface implementation ##
|
||||
// #######################################
|
||||
|
||||
@Override
|
||||
public int compareTo(Object arg0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "minetweaker";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return StringUtil.join(new String[] {
|
||||
"",
|
||||
"minetweaker reload",
|
||||
" Reloads all scripts",
|
||||
"minetweaker names",
|
||||
" Outputs a list of all item names in the game to the minetweaker log",
|
||||
"minetweaker liquids",
|
||||
" Outputs a list of all liquid names in the game to the minetweaker log",
|
||||
"minetweaker inventory",
|
||||
" Lists all items in your inventory",
|
||||
"minetweaker hand",
|
||||
" Outputs the name of the item in your hand",
|
||||
"minetweaker oredict",
|
||||
" Outputs all ore dictionary entries in the game to the minetweaker log",
|
||||
"minetweaker oredict <name>",
|
||||
" Outputs all items in the given ore dictionary entry to the minetweaker log",
|
||||
"minetweaker mods",
|
||||
" Outputs all active mod IDs in the game",
|
||||
"minetweaker name <id>",
|
||||
" Outputs the name for the given item ID"
|
||||
}, "\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getCommandAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender icommandsender, String[] arguments) {
|
||||
if (arguments.length == 0) {
|
||||
sendChatMessage(icommandsender, "Please provide a command. Use /help minetweaker for more info.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (arguments[0].equals("reload")) {
|
||||
MineTweakerMod.INSTANCE.reload();
|
||||
|
||||
String message = "Scripts have been reloaded";
|
||||
sendChatMessage(icommandsender, message);
|
||||
} else if (arguments[0].equals("names")) {
|
||||
for (Item item : Item.itemsList) {
|
||||
if (item == null) continue;
|
||||
|
||||
String key = item.getUnlocalizedName();
|
||||
|
||||
String displayName = "";
|
||||
|
||||
try {
|
||||
displayName = " -- " + new ItemStack(item, 1, 0).getDisplayName();
|
||||
} catch (Exception ex) {
|
||||
// some mods (such as buildcraft) may throw exceptions when calling
|
||||
// getDisplayName on a item stack that doesn't contain valid NBT data
|
||||
}
|
||||
|
||||
String message = "<" + key + ">" + displayName;
|
||||
MineTweakerAPI.logger.logCommand(message);
|
||||
}
|
||||
sendChatMessage(icommandsender, "List generated; see minetweaker.log in your minecraft dir");
|
||||
} else if (arguments[0].equals("liquids")) {
|
||||
for (Map.Entry<String, Fluid> entry : FluidRegistry.getRegisteredFluids().entrySet()) {
|
||||
String message = "<liquid:" + entry.getKey() + "> -- " + entry.getValue().getLocalizedName();
|
||||
MineTweakerAPI.logger.logCommand(message);
|
||||
sendChatMessage(icommandsender, "List generated; see minetweaker.log in your minecraft dir");
|
||||
}
|
||||
} else if (arguments[0].equals("inventory")) {
|
||||
if (icommandsender instanceof EntityPlayer) {
|
||||
InventoryPlayer inventory = ((EntityPlayer) icommandsender).inventory;
|
||||
for(int i = 0; i < inventory.getSizeInventory(); i++) {
|
||||
ItemStack stack = inventory.getStackInSlot(i);
|
||||
if (stack != null) {
|
||||
StringBuilder description = new StringBuilder();
|
||||
description.append('<');
|
||||
description.append(stack.getItem().getUnlocalizedName());
|
||||
if (stack.getItemDamage() > 0) {
|
||||
description.append(':').append(stack.getItemDamage());
|
||||
}
|
||||
description.append('>');
|
||||
|
||||
if (stack.stackSize != 1) {
|
||||
description.append('*').append(stack.stackSize);
|
||||
}
|
||||
|
||||
sendChatMessage(icommandsender, new MCItemStack(stack).toString());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sendChatMessage(icommandsender, "Inventory command can only be executed by players");
|
||||
}
|
||||
} else if (arguments[0].equals("hand")) {
|
||||
if (icommandsender instanceof EntityPlayer) {
|
||||
InventoryPlayer inventory = ((EntityPlayer) icommandsender).inventory;
|
||||
ItemStack stack = inventory.getCurrentItem();
|
||||
if (stack != null) {
|
||||
StringBuilder description = new StringBuilder();
|
||||
description.append('<');
|
||||
description.append(stack.getItem().getUnlocalizedName());
|
||||
if (stack.getItemDamage() > 0) {
|
||||
description.append(':').append(stack.getItemDamage());
|
||||
}
|
||||
description.append('>');
|
||||
|
||||
if (stack.stackSize != 1) {
|
||||
description.append('*').append(stack.stackSize);
|
||||
}
|
||||
|
||||
sendChatMessage(icommandsender, new MCItemStack(stack).toString());
|
||||
}
|
||||
} else {
|
||||
sendChatMessage(icommandsender, "Hand command can only be executed by players");
|
||||
}
|
||||
} else if (arguments[0].equals("oredict")) {
|
||||
if (arguments.length > 2) {
|
||||
String entryName = arguments[2];
|
||||
List<ItemStack> ores = OreDictionary.getOres(entryName);
|
||||
if (ores.isEmpty()) {
|
||||
sendChatMessage(icommandsender, "Entry doesn't exist");
|
||||
return;
|
||||
} else {
|
||||
MineTweakerAPI.logger.logCommand("Ore entries for " + entryName + ":");
|
||||
for (ItemStack ore : ores) {
|
||||
MineTweakerAPI.logger.logCommand(" " + new MCItemStack(ore).toString());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (String entryName : OreDictionary.getOreNames()) {
|
||||
MineTweakerAPI.logger.logCommand("Ore entries for " + entryName + ":");
|
||||
List<ItemStack> ores = OreDictionary.getOres(entryName);
|
||||
for (ItemStack ore : ores) {
|
||||
MineTweakerAPI.logger.logCommand(" " + new MCItemStack(ore).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
sendChatMessage(icommandsender, "List generated; see minetweaker.log in your minecraft dir");
|
||||
} else if (arguments[0].equals("mods")) {
|
||||
List<ModContainer> mods = Loader.instance().getActiveModList();
|
||||
MineTweakerAPI.logger.logCommand("Mods list:");
|
||||
for (ModContainer mod : mods) {
|
||||
sendChatMessage(icommandsender, mod.getModId());
|
||||
MineTweakerAPI.logger.logCommand("Mod: " + mod.getModId());
|
||||
}
|
||||
} else if (arguments[0].equals("name")) {
|
||||
if (arguments.length < 2) {
|
||||
sendChatMessage(icommandsender, "missing id parameter");
|
||||
} else {
|
||||
try {
|
||||
int id = Integer.parseInt(arguments[1]);
|
||||
if (id < 0 || id >= Item.itemsList.length || Item.itemsList[id] == null) {
|
||||
sendChatMessage(icommandsender, "invalid id");
|
||||
} else {
|
||||
Item item = Item.itemsList[id];
|
||||
StringBuilder description = new StringBuilder();
|
||||
description.append('<');
|
||||
description.append(item.getUnlocalizedName());
|
||||
description.append('>');
|
||||
sendChatMessage(icommandsender, description.toString());
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
MineTweakerAPI.logger.logCommand("ID must be an integer");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*if (arguments[0].equals("name")) {
|
||||
if (arguments.length < 2) {
|
||||
sendChatMessage(icommandsender, "Please provide an item id");
|
||||
} else {
|
||||
try {
|
||||
ITweakerItem item = TweakerItem.parse(arguments[1]);
|
||||
sendChatMessage(icommandsender, "Name for " + item.toIdString() + ": " + MineTweakerUtil.formatItemName(item.getName()));
|
||||
} catch (TweakerExecuteException ex) {
|
||||
sendChatMessage(icommandsender, ex.getMessage());
|
||||
} catch (TweakerException ex) {
|
||||
sendChatMessage(icommandsender, ex.getExplanation());
|
||||
}
|
||||
}
|
||||
} else if (arguments[0].equals("liquid")) {
|
||||
if (arguments.length < 2) {
|
||||
sendChatMessage(icommandsender, "Please provide a liquid container item id");
|
||||
} else {
|
||||
try {
|
||||
TweakerItem item = TweakerItem.parse(arguments[1]);
|
||||
//#ifdef MC152
|
||||
//+if (LiquidContainerRegistry.isLiquid(item.make(1))) {
|
||||
//+sendChatMessage(icommandsender, "Liquid name: " + item.getName());
|
||||
//+} else if (LiquidContainerRegistry.isFilledContainer(item.make(1))) {
|
||||
//+sendChatMessage(icommandsender, "Liquid name: " + LiquidContainerRegistry.getLiquidForFilledItem(item.make(1)).asItemStack().getItemName());
|
||||
//+} else {
|
||||
//+sendChatMessage(icommandsender, "This item is not a liquid or liquid container");
|
||||
//+}
|
||||
//#else
|
||||
if (item.getItemId() == 9) {
|
||||
sendChatMessage(icommandsender, "Liquid name: fluid.tile.water");
|
||||
} else if (item.getItemId() == 11) {
|
||||
sendChatMessage(icommandsender, "Liquid name: fluid.tile.lava");
|
||||
} else if (Block.blocksList[item.getItemId()] != null && Block.blocksList[item.getItemId()] instanceof IFluidBlock) {
|
||||
sendChatMessage(icommandsender, "Liquid name: " + ((IFluidBlock)(Block.blocksList[item.getItemId()])).getFluid().getUnlocalizedName());
|
||||
} else if (FluidContainerRegistry.isFilledContainer(item.make(1))) {
|
||||
sendChatMessage(icommandsender, "Liquid name: " + FluidContainerRegistry.getFluidForFilledItem(item.make(1)).getFluid().getUnlocalizedName());
|
||||
} else {
|
||||
sendChatMessage(icommandsender, "This item is not a liquid or liquid container");
|
||||
}
|
||||
//#endif
|
||||
} catch (TweakerExecuteException ex) {
|
||||
sendChatMessage(icommandsender, ex.getMessage());
|
||||
} catch (TweakerException ex) {
|
||||
sendChatMessage(icommandsender, ex.getExplanation());
|
||||
}
|
||||
}
|
||||
} else if (arguments[0].equals("oredict")) {
|
||||
if (arguments.length == 1) {
|
||||
String[] names = OreDictionary.getOreNames();
|
||||
Arrays.sort(names);
|
||||
for (String name : names) {
|
||||
sendChatMessage(icommandsender, "[" + name + "]");
|
||||
ArrayList<ItemStack> entries = OreDictionary.getOres(name);
|
||||
for (ItemStack stack : entries) {
|
||||
//#ifdef MC152
|
||||
//+sendChatMessage(icommandsender,
|
||||
//+" " + MineTweakerUtil.getItemString(stack) + " - " +
|
||||
//+MineTweakerUtil.formatItemName(stack.getItemDamage() == OreDictionary.WILDCARD_VALUE ? stack.getItem().getUnlocalizedName() : stack.getItemName()));
|
||||
//#else
|
||||
sendChatMessage(icommandsender,
|
||||
" " + MineTweakerUtil.getItemString(stack) + " - " +
|
||||
MineTweakerUtil.formatItemName(stack.getItemDamage() == OreDictionary.WILDCARD_VALUE ? stack.getItem().getUnlocalizedName() : stack.getUnlocalizedName()));
|
||||
//#endif
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
if (Character.isDigit(arguments[1].charAt(0))) {
|
||||
TweakerItemPattern item = TweakerItem.parse(arguments[1]).asItemPattern();
|
||||
for (String name : OreDictionary.getOreNames()) {
|
||||
for (ItemStack stack : OreDictionary.getOres(name)) {
|
||||
if (item.matches(stack)) {
|
||||
sendChatMessage(icommandsender, " " + name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (ItemStack stack : OreDictionary.getOres(arguments[1])) {
|
||||
//#ifdef MC152
|
||||
//+sendChatMessage(icommandsender,
|
||||
//+" " + MineTweakerUtil.getItemString(stack) + " - " +
|
||||
//+MineTweakerUtil.formatItemName(stack.getItemDamage() == OreDictionary.WILDCARD_VALUE ? stack.getItem().getUnlocalizedName() : stack.getItemName()));
|
||||
//#else
|
||||
sendChatMessage(icommandsender,
|
||||
" " + MineTweakerUtil.getItemString(stack) + " - " +
|
||||
MineTweakerUtil.formatItemName(stack.getItemDamage() == OreDictionary.WILDCARD_VALUE ? stack.getItem().getUnlocalizedName() : stack.getUnlocalizedName()));
|
||||
//#endif
|
||||
}
|
||||
}
|
||||
} catch (TweakerExecuteException ex) {
|
||||
sendChatMessage(icommandsender, "Invalid item id or ore dictionary entry");
|
||||
} catch (TweakerException ex) {
|
||||
sendChatMessage(icommandsender, "Invalid item id or ore dictionary entry");
|
||||
}
|
||||
}
|
||||
} else if (arguments[0].equals("recipes")) {
|
||||
if (arguments.length < 2) {
|
||||
sendChatMessage(icommandsender, "Please provide an item id");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
TweakerItem item = TweakerItem.parse(arguments[1]);
|
||||
sendChatMessage(icommandsender, "Recipes for item " + item.toIdString());
|
||||
|
||||
TweakerItemPattern pattern = item.asItemPattern();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
|
||||
|
||||
for (IRecipe recipe : recipes) {
|
||||
if (pattern.matches(recipe.getRecipeOutput())) {
|
||||
sendChatMessage(icommandsender, " " + MineTweakerUtil.getRecipeString(recipe));
|
||||
}
|
||||
}
|
||||
} catch (TweakerExecuteException ex) {
|
||||
sendChatMessage(icommandsender, "Invalid item id");
|
||||
} catch (TweakerException ex) {
|
||||
sendChatMessage(icommandsender, "Invalid item id");
|
||||
}
|
||||
} else if (arguments[0].equals("fuel")) {
|
||||
if (arguments.length < 2) {
|
||||
sendChatMessage(icommandsender, "Please provide an item id");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
TweakerItem item = TweakerItem.parse(arguments[1]);
|
||||
ItemStack stack = item.make(1);
|
||||
int value = TileEntityFurnace.getItemBurnTime(stack);
|
||||
int regValue = GameRegistry.getFuelValue(stack);
|
||||
|
||||
sendChatMessage(icommandsender, "Fuel for " + item.toIdString() + " = " + value);
|
||||
if (value != regValue) {
|
||||
sendChatMessage(icommandsender, "The value is hardcoded and cannot be altered.");
|
||||
}
|
||||
} catch (TweakerExecuteException ex) {
|
||||
sendChatMessage(icommandsender, "Invalid item id");
|
||||
} catch (TweakerException ex) {
|
||||
sendChatMessage(icommandsender, "Invalid item id");
|
||||
}
|
||||
} else if (arguments[0].equals("reload")) {
|
||||
if (!MineTweaker.instance.canRollback()) {
|
||||
sendChatMessage(icommandsender, "Previous server script contained permanent actions, cannot reload. A restart is required to reload scripts.");
|
||||
} else {
|
||||
MineTweaker.instance.reloadScripts();
|
||||
sendChatMessage(icommandsender, "Script reloaded, updating all players");
|
||||
}
|
||||
} else if (arguments[0].equals("logdamage=on")) {
|
||||
DamageTweaker.logDamage = true;
|
||||
sendChatMessage(icommandsender, "Damage logging turned on");
|
||||
sendChatMessage(icommandsender, "Info: logging is sent to the development console");
|
||||
} else if (arguments[0].equals("logdamage=off")) {
|
||||
DamageTweaker.logDamage = false;
|
||||
sendChatMessage(icommandsender, "Damage logging turned off");
|
||||
} else {
|
||||
sendChatMessage(icommandsender, "Unrecognized minetweaker command");
|
||||
}*/
|
||||
|
||||
//MineCraftCompat.sendChatMessage(icommandsender, "[" + Arrays2.join(arguments, ", ") + "]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender icommandsender) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<?> addTabCompletionOptions(ICommandSender icommandsender,
|
||||
String[] astring) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsernameIndex(String[] astring, int i) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import minetweaker.runtime.ILogger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MineTweakerLogger implements ILogger {
|
||||
private Writer writer;
|
||||
|
||||
public MineTweakerLogger() {
|
||||
File logFile = new File("minetweaker.log");
|
||||
if (logFile.exists()) logFile.delete();
|
||||
|
||||
try {
|
||||
writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(logFile)));
|
||||
} catch (IOException ex) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logCommand(String message) {
|
||||
try {
|
||||
writer.append("COMMAND: ");
|
||||
writer.append(message);
|
||||
writer.append('\n');
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
|
||||
}
|
||||
|
||||
System.out.println("COMMAND: " + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logInfo(String message) {
|
||||
try {
|
||||
writer.append("INFO: ");
|
||||
writer.append(message);
|
||||
writer.append('\n');
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
|
||||
}
|
||||
|
||||
System.out.println("INFO: " + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logWarning(String message) {
|
||||
try {
|
||||
writer.append("WARNING: ");
|
||||
writer.append(message);
|
||||
writer.append('\n');
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
|
||||
}
|
||||
|
||||
System.out.println("WARNING: " + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message) {
|
||||
try {
|
||||
writer.append("ERROR: ");
|
||||
writer.append(message);
|
||||
writer.append('\n');
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
|
||||
}
|
||||
|
||||
System.out.println("ERROR: " + message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164;
|
||||
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.Mod.EventHandler;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStartingEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStoppedEvent;
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import java.io.File;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.mc164.furnace.FuelTweaker;
|
||||
import minetweaker.mc164.furnace.MCFurnaceManager;
|
||||
import minetweaker.mc164.mods.MCLoadedMods;
|
||||
import minetweaker.mc164.network.MCPacketHandler;
|
||||
import minetweaker.mc164.oredict.MCOreDict;
|
||||
import minetweaker.mc164.recipes.MCRecipeManager;
|
||||
import minetweaker.mc164.util.MineTweakerHacks;
|
||||
import minetweaker.runtime.IScriptProvider;
|
||||
import minetweaker.runtime.providers.ScriptProviderCascade;
|
||||
import minetweaker.runtime.providers.ScriptProviderDirectory;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
|
||||
/**
|
||||
* Main mod class. Performs some general logic, initialization of the API and
|
||||
* FML event handling.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@Mod(modid = MineTweakerMod.MODID, version = MineTweakerMod.MCVERSION + "-3.0.0")
|
||||
public class MineTweakerMod {
|
||||
public static final String MODID = "MineTweaker";
|
||||
public static final String MCVERSION = "1.7.2";
|
||||
|
||||
private static final String[] REGISTRIES = {
|
||||
"minetweaker.mods.ic2.ClassRegistry",
|
||||
"minetweaker.mods.nei.ClassRegistry"
|
||||
};
|
||||
|
||||
@Mod.Instance(MODID)
|
||||
public static MineTweakerMod INSTANCE;
|
||||
|
||||
private final IScriptProvider scriptsGlobal;
|
||||
|
||||
private boolean iAmServer = false;
|
||||
|
||||
public MineTweakerMod() {
|
||||
MineTweakerAPI.oreDict = new MCOreDict();
|
||||
MineTweakerAPI.recipes = new MCRecipeManager();
|
||||
MineTweakerAPI.logger = new MineTweakerLogger();
|
||||
MineTweakerAPI.furnace = new MCFurnaceManager();
|
||||
MineTweakerAPI.loadedMods = new MCLoadedMods();
|
||||
|
||||
File globalDir = new File("scripts");
|
||||
if (!globalDir.exists()) {
|
||||
globalDir.mkdirs();
|
||||
}
|
||||
|
||||
scriptsGlobal = new ScriptProviderDirectory(globalDir);
|
||||
MineTweakerAPI.tweaker.setScriptProvider(scriptsGlobal);
|
||||
}
|
||||
|
||||
public boolean iAmServer() {
|
||||
return iAmServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads all scripts.
|
||||
*/
|
||||
public void reload() {
|
||||
MineTweakerAPI.tweaker.rollback();
|
||||
MineTweakerAPI.tweaker.load();
|
||||
|
||||
if (iAmServer) {
|
||||
// execute script on all connected clients
|
||||
Packet packet = new Packet250CustomPayload(
|
||||
MCPacketHandler.CHANNEL_SERVERSCRIPT,
|
||||
MineTweakerAPI.tweaker.getScriptData());
|
||||
PacketDispatcher.sendPacketToAllPlayers(packet);
|
||||
}
|
||||
}
|
||||
|
||||
// ##########################
|
||||
// ### FML Event Handlers ###
|
||||
// ##########################
|
||||
|
||||
@EventHandler
|
||||
public void onLoad(FMLPreInitializationEvent ev) {
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPostInit(FMLPostInitializationEvent ev) {
|
||||
MineTweakerAPI.registerClassRegistry(MineTweakerRegistry.class);
|
||||
|
||||
for (String registry : REGISTRIES) {
|
||||
MineTweakerAPI.registerClassRegistry(registry);
|
||||
}
|
||||
|
||||
FuelTweaker.INSTANCE.register();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerAboutToStart(FMLServerAboutToStartEvent ev) {
|
||||
// starts before loading worlds
|
||||
// perfect place to start MineTweaker!
|
||||
|
||||
File scriptsDir = new File(MineTweakerHacks.getWorldDirectory(ev.getServer()), "scripts");
|
||||
if (!scriptsDir.exists()) {
|
||||
scriptsDir.mkdir();
|
||||
}
|
||||
|
||||
iAmServer = true;
|
||||
|
||||
IScriptProvider scriptsLocal = new ScriptProviderDirectory(scriptsDir);
|
||||
IScriptProvider cascaded = new ScriptProviderCascade(scriptsGlobal, scriptsLocal);
|
||||
MineTweakerAPI.tweaker.setScriptProvider(cascaded);
|
||||
reload();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerStarting(FMLServerStartingEvent ev) {
|
||||
ev.registerServerCommand(new MineTweakerCommand());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerStopped(FMLServerStoppedEvent ev) {
|
||||
iAmServer = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MineTweakerRegistry {
|
||||
public static void getClasses(List<Class> classes) {
|
||||
// method stub, actual content is generated by build process
|
||||
}
|
||||
}
|
||||
+176
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.brackets;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import minetweaker.IBracketHandler;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.BracketHandler;
|
||||
import minetweaker.mc164.item.MCItemStack;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.IngredientAny;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import stanhebben.zenscript.ZenTokener;
|
||||
import stanhebben.zenscript.expression.ExpressionInt;
|
||||
import stanhebben.zenscript.expression.ExpressionJavaCallStatic;
|
||||
import stanhebben.zenscript.expression.ExpressionString;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.parser.Token;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.type.natives.JavaMethod;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@BracketHandler(priority=100)
|
||||
public class ItemBracketHandler implements IBracketHandler {
|
||||
private static final Map<String, Item> itemNames;
|
||||
|
||||
static {
|
||||
itemNames = new HashMap<String, Item>();
|
||||
for (Item item : Item.itemsList) {
|
||||
if (item == null) continue;
|
||||
|
||||
itemNames.put(item.getUnlocalizedName(), item);
|
||||
}
|
||||
}
|
||||
|
||||
public static IItemStack getItem(String name, int meta) {
|
||||
Item item = itemNames.get(name);
|
||||
if (item != null) {
|
||||
return new MCItemStack(new ItemStack(item, 1, meta), true);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static IItemStack getItem(int id, int meta) {
|
||||
Item item = Item.itemsList[id];
|
||||
if (item != null) {
|
||||
return new MCItemStack(new ItemStack(item, 1, meta), true);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private final IZenSymbol symbolAny;
|
||||
private final JavaMethod method;
|
||||
private final JavaMethod method2;
|
||||
|
||||
public ItemBracketHandler() {
|
||||
symbolAny = MineTweakerAPI.getJavaStaticFieldSymbol(IngredientAny.class, "INSTANCE");
|
||||
method = MineTweakerAPI.getJavaMethod(
|
||||
ItemBracketHandler.class,
|
||||
"getItem",
|
||||
String.class, int.class);
|
||||
method2 = MineTweakerAPI.getJavaMethod(
|
||||
ItemBracketHandler.class,
|
||||
"getItem",
|
||||
int.class, int.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZenSymbol resolve(List<Token> tokens) {
|
||||
// any symbol
|
||||
if (tokens.size() == 1 && tokens.get(0).getValue().equals("*")) {
|
||||
return symbolAny;
|
||||
}
|
||||
|
||||
// detect special cases:
|
||||
// item: at the start means item-specific syntax
|
||||
// :xxx with xxx an integer means sub-item syntax
|
||||
// :* means any-subitem-syntax
|
||||
int fromIndex = 0;
|
||||
int toIndex = tokens.size();
|
||||
int meta = 0;
|
||||
|
||||
if (tokens.size() > 2) {
|
||||
if (tokens.get(0).getValue().equals("item") && tokens.get(1).getValue().equals(":")) {
|
||||
fromIndex = 2;
|
||||
}
|
||||
if (tokens.get(tokens.size() - 1).getType() == ZenTokener.T_INTVALUE
|
||||
&& tokens.get(tokens.size() - 2).getValue().equals(":")) {
|
||||
toIndex = tokens.size() - 2;
|
||||
meta = Integer.parseInt(tokens.get(tokens.size() - 1).getValue());
|
||||
} else if (tokens.get(tokens.size() - 1).getValue().equals("*")
|
||||
&& tokens.get(tokens.size() - 2).getValue().equals(":")) {
|
||||
toIndex = tokens.size() - 2;
|
||||
meta = OreDictionary.WILDCARD_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
return find(tokens, fromIndex, toIndex, meta);
|
||||
}
|
||||
|
||||
private IZenSymbol find(List<Token> tokens, int startIndex, int endIndex, int meta) {
|
||||
if (tokens.size() == 1 && tokens.get(0).getType() == ZenTokener.T_INTVALUE) {
|
||||
int id = Integer.parseInt(tokens.get(0).getValue());
|
||||
if (id < 0 || id > Item.itemsList.length || Item.itemsList[id] == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ItemReferenceSymbolId(id, meta);
|
||||
}
|
||||
|
||||
StringBuilder valueBuilder = new StringBuilder();
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
Token token = tokens.get(i);
|
||||
valueBuilder.append(token.getValue());
|
||||
}
|
||||
|
||||
if (itemNames.containsKey(valueBuilder.toString())) {
|
||||
return new ItemReferenceSymbol(valueBuilder.toString(), meta);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private class ItemReferenceSymbol implements IZenSymbol {
|
||||
private final String name;
|
||||
private final int meta;
|
||||
|
||||
public ItemReferenceSymbol(String name, int meta) {
|
||||
this.name = name;
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression instance(ZenPosition position) {
|
||||
return new ExpressionJavaCallStatic(
|
||||
position,
|
||||
method,
|
||||
new ExpressionString(position, name),
|
||||
new ExpressionInt(position, meta, ZenType.INT));
|
||||
}
|
||||
}
|
||||
|
||||
private class ItemReferenceSymbolId implements IZenSymbol {
|
||||
private final int id;
|
||||
private final int meta;
|
||||
|
||||
public ItemReferenceSymbolId(int id, int meta) {
|
||||
this.id = id;
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression instance(ZenPosition position) {
|
||||
return new ExpressionJavaCallStatic(
|
||||
position,
|
||||
method2,
|
||||
new ExpressionInt(position, id, ZenType.INT),
|
||||
new ExpressionInt(position, meta, ZenType.INT));
|
||||
}
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package minetweaker.mc164.brackets;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.IBracketHandler;
|
||||
import minetweaker.annotations.BracketHandler;
|
||||
import minetweaker.mc164.liquid.MCLiquidStack;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.runtime.GlobalRegistry;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import stanhebben.zenscript.expression.ExpressionJavaCallStatic;
|
||||
import stanhebben.zenscript.expression.ExpressionString;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.parser.Token;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.type.natives.JavaMethod;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@BracketHandler
|
||||
public class LiquidBracketHandler implements IBracketHandler {
|
||||
public static ILiquidStack getLiquid(String name) {
|
||||
Fluid fluid = FluidRegistry.getFluid(name);
|
||||
if (fluid != null) {
|
||||
return new MCLiquidStack(new FluidStack(fluid, 1));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZenSymbol resolve(List<Token> tokens) {
|
||||
if (tokens.size() > 2) {
|
||||
if (tokens.get(0).getValue().equals("liquid") && tokens.get(1).getValue().equals(":")) {
|
||||
return find(tokens, 2, tokens.size());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private IZenSymbol find(List<Token> tokens, int startIndex, int endIndex) {
|
||||
StringBuilder valueBuilder = new StringBuilder();
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
Token token = tokens.get(i);
|
||||
valueBuilder.append(token.getValue());
|
||||
}
|
||||
|
||||
Fluid fluid = FluidRegistry.getFluid(valueBuilder.toString());
|
||||
if (fluid != null) {
|
||||
return new LiquidReferenceSymbol(valueBuilder.toString());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private class LiquidReferenceSymbol implements IZenSymbol {
|
||||
private final String name;
|
||||
|
||||
public LiquidReferenceSymbol(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression instance(ZenPosition position) {
|
||||
JavaMethod method = JavaMethod.get(
|
||||
GlobalRegistry.getTypeRegistry(),
|
||||
LiquidBracketHandler.class,
|
||||
"getLiquid",
|
||||
String.class);
|
||||
|
||||
return new ExpressionJavaCallStatic(
|
||||
position,
|
||||
method,
|
||||
new ExpressionString(position, name));
|
||||
}
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.brackets;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.IBracketHandler;
|
||||
import minetweaker.annotations.BracketHandler;
|
||||
import minetweaker.mc164.oredict.MCOreDictEntry;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import minetweaker.runtime.GlobalRegistry;
|
||||
import stanhebben.zenscript.expression.ExpressionJavaCallStatic;
|
||||
import stanhebben.zenscript.expression.ExpressionString;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.parser.Token;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.type.natives.JavaMethod;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@BracketHandler
|
||||
public class OreBracketHandler implements IBracketHandler {
|
||||
public static IOreDictEntry getOre(String name) {
|
||||
return new MCOreDictEntry(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZenSymbol resolve(List<Token> tokens) {
|
||||
if (tokens.size() > 2) {
|
||||
if (tokens.get(0).getValue().equals("ore") && tokens.get(1).getValue().equals(":")) {
|
||||
return find(tokens, 2, tokens.size());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private IZenSymbol find(List<Token> tokens, int startIndex, int endIndex) {
|
||||
StringBuilder valueBuilder = new StringBuilder();
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
Token token = tokens.get(i);
|
||||
valueBuilder.append(token.getValue());
|
||||
}
|
||||
|
||||
return new OreReferenceSymbol(valueBuilder.toString());
|
||||
}
|
||||
|
||||
private class OreReferenceSymbol implements IZenSymbol {
|
||||
private final String name;
|
||||
|
||||
public OreReferenceSymbol(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression instance(ZenPosition position) {
|
||||
JavaMethod method = JavaMethod.get(
|
||||
GlobalRegistry.getTypeRegistry(),
|
||||
OreBracketHandler.class,
|
||||
"getOre",
|
||||
String.class);
|
||||
|
||||
return new ExpressionJavaCallStatic(
|
||||
position,
|
||||
method,
|
||||
new ExpressionString(position, name));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import minetweaker.mc164.util.MineTweakerHacks;
|
||||
import minetweaker.api.data.DataByte;
|
||||
import minetweaker.api.data.DataByteArray;
|
||||
import minetweaker.api.data.DataDouble;
|
||||
import minetweaker.api.data.DataFloat;
|
||||
import minetweaker.api.data.DataInt;
|
||||
import minetweaker.api.data.DataIntArray;
|
||||
import minetweaker.api.data.DataList;
|
||||
import minetweaker.api.data.DataLong;
|
||||
import minetweaker.api.data.DataMap;
|
||||
import minetweaker.api.data.DataShort;
|
||||
import minetweaker.api.data.DataString;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.data.IDataConverter;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagByte;
|
||||
import net.minecraft.nbt.NBTTagByteArray;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagDouble;
|
||||
import net.minecraft.nbt.NBTTagFloat;
|
||||
import net.minecraft.nbt.NBTTagInt;
|
||||
import net.minecraft.nbt.NBTTagIntArray;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagLong;
|
||||
import net.minecraft.nbt.NBTTagShort;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class NBTConverter implements IDataConverter<NBTBase> {
|
||||
private static final NBTConverter INSTANCE = new NBTConverter();
|
||||
|
||||
public static NBTBase from(IData data) {
|
||||
return data.convert(INSTANCE);
|
||||
}
|
||||
|
||||
public static IData from(NBTBase nbt, boolean immutable) {
|
||||
if (nbt == null) return null;
|
||||
|
||||
switch (nbt.getId()) {
|
||||
case 1: // byte
|
||||
return new DataByte(((NBTTagByte) nbt).data);
|
||||
case 2: // short
|
||||
return new DataShort(((NBTTagShort) nbt).data);
|
||||
case 3: // int
|
||||
return new DataInt(((NBTTagInt) nbt).data);
|
||||
case 4: // long
|
||||
return new DataLong(((NBTTagLong) nbt).data);
|
||||
case 5: // float
|
||||
return new DataFloat(((NBTTagFloat) nbt).data);
|
||||
case 6: // double
|
||||
return new DataDouble(((NBTTagDouble) nbt).data);
|
||||
case 7: // byte[]
|
||||
return new DataByteArray(((NBTTagByteArray) nbt).byteArray, immutable);
|
||||
case 8: // string
|
||||
return new DataString(((NBTTagString) nbt).data);
|
||||
case 9: { // list
|
||||
NBTTagList listTag = (NBTTagList) nbt;
|
||||
List<IData> values = new ArrayList<IData>();
|
||||
for (int i = 0; i < listTag.tagCount(); i++) {
|
||||
values.add(from(listTag.tagAt(i), immutable));
|
||||
}
|
||||
return new DataList(values, immutable);
|
||||
}
|
||||
case 10: { // compound
|
||||
Map<String, IData> values = new HashMap<String, IData>();
|
||||
NBTTagCompound original = (NBTTagCompound) nbt;
|
||||
Map<String, NBTBase> tagMap = MineTweakerHacks.getNBTCompoundMap(original);
|
||||
for (String key : tagMap.keySet()) {
|
||||
values.put(key, from(original.getTag(key), immutable));
|
||||
}
|
||||
return new DataMap(values, immutable);
|
||||
}
|
||||
case 11: // int[]
|
||||
return new DataIntArray(((NBTTagIntArray) nbt).intArray, immutable);
|
||||
default:
|
||||
throw new RuntimeException("Unknown tag type: " + nbt.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateMap(NBTTagCompound nbt, IData data) {
|
||||
NBTUpdater updater = new NBTUpdater(nbt);
|
||||
data.convert(updater);
|
||||
}
|
||||
|
||||
public NBTConverter() {}
|
||||
|
||||
@Override
|
||||
public NBTBase fromBool(boolean value) {
|
||||
return new NBTTagInt(null, value ? 1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromByte(byte value) {
|
||||
return new NBTTagByte(null, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromShort(short value) {
|
||||
return new NBTTagShort(null, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromInt(int value) {
|
||||
return new NBTTagInt(null, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromLong(long value) {
|
||||
return new NBTTagLong(null, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromFloat(float value) {
|
||||
return new NBTTagFloat(null, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromDouble(double value) {
|
||||
return new NBTTagDouble(null, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromString(String value) {
|
||||
return new NBTTagString(null, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromList(List<IData> values) {
|
||||
NBTTagList result = new NBTTagList();
|
||||
for (IData value : values) {
|
||||
result.appendTag(from(value));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromMap(Map<String, IData> values) {
|
||||
NBTTagCompound result = new NBTTagCompound();
|
||||
for (Map.Entry<String, IData> entry : values.entrySet()) {
|
||||
result.setTag(entry.getKey(), from(entry.getValue()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromByteArray(byte[] value) {
|
||||
return new NBTTagByteArray(null, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromIntArray(int[] value) {
|
||||
return new NBTTagIntArray(null, value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.data;
|
||||
|
||||
import java.util.Map;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.data.IDataConverter;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class NBTUpdater extends NBTConverter implements IDataConverter<NBTBase> {
|
||||
private final NBTTagCompound nbt;
|
||||
|
||||
public NBTUpdater(NBTTagCompound compound) {
|
||||
this.nbt = compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromMap(Map<String, IData> map) {
|
||||
for (Map.Entry<String, IData> entry : map.entrySet()) {
|
||||
if (nbt.hasKey(entry.getKey())) {
|
||||
if (entry.getValue() == null) {
|
||||
nbt.removeTag(entry.getKey());
|
||||
} else {
|
||||
if (nbt.getTag(entry.getKey()).getId() == 10) {
|
||||
NBTTagCompound tag = (NBTTagCompound) nbt.getTag(entry.getKey());
|
||||
nbt.setTag(entry.getKey(), entry.getValue().convert(new NBTUpdater(nbt)));
|
||||
} else {
|
||||
nbt.setTag(entry.getKey(), NBTConverter.from(entry.getValue()));
|
||||
}
|
||||
}
|
||||
} else if (entry.getValue() != null) {
|
||||
nbt.setTag(entry.getKey(), from(entry.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
return nbt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.furnace;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import cpw.mods.fml.common.IFuelHandler;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.mc164.item.MCItemStack;
|
||||
|
||||
public class FuelTweaker {
|
||||
public static final FuelTweaker INSTANCE = new FuelTweaker();
|
||||
|
||||
private List<IFuelHandler> original;
|
||||
private final HashMap<String, List<SetFuelPattern>> quickList = new HashMap<String, List<SetFuelPattern>>();
|
||||
|
||||
private FuelTweaker() {}
|
||||
|
||||
public void register() {
|
||||
try {
|
||||
Field fuelHandlers = GameRegistry.class.getDeclaredField("fuelHandlers");
|
||||
fuelHandlers.setAccessible(true);
|
||||
original = (List<IFuelHandler>) fuelHandlers.get(null);
|
||||
List<IFuelHandler> modified = new ArrayList<IFuelHandler>();
|
||||
modified.add(new OverridingFuelHandler());
|
||||
fuelHandlers.set(null, modified);
|
||||
} catch (NoSuchFieldException ex) {
|
||||
System.out.println("[MineTweaker] Error: could not get GameRegistry fuel handlers field. Cannot use custom fuel values.");
|
||||
} catch (SecurityException ex) {
|
||||
System.out.println("[MineTweaker] Error: could not alter GameRegistry fuel handlers field. Cannot use custom fuel values.");
|
||||
} catch (IllegalAccessException ex) {
|
||||
System.out.println("[MineTweaker] Error: could not alter GameRegistry fuel handlers field. Cannot use custom fuel values.");
|
||||
}
|
||||
}
|
||||
|
||||
public void addFuelPattern(SetFuelPattern pattern) {
|
||||
List<IItemStack> items = pattern.getPattern().getItems();
|
||||
if (items == null) {
|
||||
MineTweakerAPI.logger.logError("Cannot set fuel for <*>");
|
||||
return;
|
||||
}
|
||||
|
||||
for (IItemStack item : pattern.getPattern().getItems()) {
|
||||
if (!quickList.containsKey(item.getName())) {
|
||||
quickList.put(item.getName(), new ArrayList<SetFuelPattern>());
|
||||
}
|
||||
quickList.get(item.getName()).add(pattern);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeFuelPattern(SetFuelPattern pattern) {
|
||||
for (IItemStack item : pattern.getPattern().getItems()) {
|
||||
if (!quickList.containsKey(item.getName())) {
|
||||
quickList.put(item.getName(), new ArrayList<SetFuelPattern>());
|
||||
}
|
||||
quickList.get(item.getName()).add(pattern);
|
||||
}
|
||||
}
|
||||
|
||||
private class OverridingFuelHandler implements IFuelHandler {
|
||||
@Override
|
||||
public int getBurnTime(ItemStack fuel) {
|
||||
IItemStack stack = new MCItemStack(fuel);
|
||||
String name = fuel.getUnlocalizedName();
|
||||
if (quickList.containsKey(name)) {
|
||||
for (SetFuelPattern override : quickList.get(name)) {
|
||||
if (override.getPattern().matches(stack)) {
|
||||
return override.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int max = 0;
|
||||
for (IFuelHandler handler : original) {
|
||||
max = Math.max(max, handler.getBurnTime(fuel));
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
}
|
||||
+222
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.furnace;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.recipes.IFurnaceManager;
|
||||
import minetweaker.mc164.item.MCItemStack;
|
||||
import minetweaker.mc164.util.MineTweakerUtil;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.FurnaceRecipes;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCFurnaceManager implements IFurnaceManager {
|
||||
public MCFurnaceManager() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(IIngredient output, IIngredient input) {
|
||||
if (output == null) throw new IllegalArgumentException("output cannot be null");
|
||||
|
||||
Map<Integer, ItemStack> smeltingList = FurnaceRecipes.smelting().getSmeltingList();
|
||||
Map<List<Integer>, ItemStack> metaSmeltingList = FurnaceRecipes.smelting().getMetaSmeltingList();
|
||||
|
||||
List<Integer> toRemove = new ArrayList<Integer>();
|
||||
List<List<Integer>> toRemoveMeta = new ArrayList<List<Integer>>();
|
||||
List<ItemStack> toRemoveValues = new ArrayList<ItemStack>();
|
||||
List<ItemStack> toRemoveMetaValues = new ArrayList<ItemStack>();
|
||||
|
||||
for (Map.Entry<Integer, ItemStack> entry : smeltingList.entrySet()) {
|
||||
if (output.matches(new MCItemStack(entry.getValue()))
|
||||
&& (input == null || input.matches(new MCItemStack(new ItemStack(entry.getKey(), 1, 0))))) {
|
||||
toRemove.add(entry.getKey());
|
||||
toRemoveValues.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<List<Integer>, ItemStack> entry : metaSmeltingList.entrySet()) {
|
||||
if (output.matches(new MCItemStack(entry.getValue()))
|
||||
&& (input == null || input.matches(new MCItemStack(new ItemStack(entry.getKey().get(0), 1, entry.getKey().get(1)))))) {
|
||||
toRemoveMeta.add(entry.getKey());
|
||||
toRemoveMetaValues.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
if (toRemove.isEmpty() && toRemoveMeta.isEmpty()) {
|
||||
MineTweakerAPI.logger.logWarning("No furnace recipes for " + output.toString());
|
||||
} else {
|
||||
MineTweakerAPI.tweaker.apply(new RemoveAction(toRemove, toRemoveValues, toRemoveMeta, toRemoveMetaValues));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRecipe(IItemStack output, IIngredient input, double xp) {
|
||||
List<IItemStack> items = input.getItems();
|
||||
if (items == null) {
|
||||
MineTweakerAPI.logger.logError("Cannot turn " + input.toString() + " into a furnace recipe");
|
||||
}
|
||||
|
||||
ItemStack[] items2 = MineTweakerUtil.getItemStacks(items);
|
||||
ItemStack output2 = (ItemStack) output.getInternal();
|
||||
MineTweakerAPI.tweaker.apply(new AddRecipeAction(input, items2, output2, xp));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFuel(IIngredient item, int fuel) {
|
||||
MineTweakerAPI.tweaker.apply(new SetFuelAction(new SetFuelPattern(item, fuel)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFuel(IItemStack item) {
|
||||
return GameRegistry.getFuelValue((ItemStack) item.getInternal());
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private static class RemoveAction implements IUndoableAction {
|
||||
private final List<Integer> items;
|
||||
private final List<ItemStack> values;
|
||||
private final List<List<Integer>> metaItems;
|
||||
private final List<ItemStack> metaValues;
|
||||
|
||||
public RemoveAction(List<Integer> items, List<ItemStack> values, List<List<Integer>> metaItems, List<ItemStack> metaValues) {
|
||||
this.items = items;
|
||||
this.values = values;
|
||||
this.metaItems = metaItems;
|
||||
this.metaValues = metaValues;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (Integer item : items) {
|
||||
FurnaceRecipes.smelting().getSmeltingList().remove(item);
|
||||
}
|
||||
for (List<Integer> item : metaItems) {
|
||||
FurnaceRecipes.smelting().getMetaSmeltingList().remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
FurnaceRecipes.smelting().getSmeltingList().put(items.get(i), values.get(i));
|
||||
}
|
||||
for (int i = 0; i < metaItems.size(); i++) {
|
||||
FurnaceRecipes.smelting().getMetaSmeltingList().put(metaItems.get(i), metaValues.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing " + items.size() + " furnace recipes";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring " + items.size() + " furnace recipes";
|
||||
}
|
||||
}
|
||||
|
||||
private static class AddRecipeAction implements IUndoableAction {
|
||||
private final IIngredient ingredient;
|
||||
private final ItemStack[] input;
|
||||
private final ItemStack output;
|
||||
private final double xp;
|
||||
|
||||
public AddRecipeAction(IIngredient ingredient, ItemStack[] input, ItemStack output, double xp) {
|
||||
this.ingredient = ingredient;
|
||||
this.input = input;
|
||||
this.output = output;
|
||||
this.xp = xp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (ItemStack inputStack : input) {
|
||||
if (inputStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
||||
FurnaceRecipes.smelting().addSmelting(inputStack.itemID, output, (float) xp);
|
||||
} else {
|
||||
FurnaceRecipes.smelting().addSmelting(inputStack.itemID, inputStack.getItemDamage(), output, (float) xp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
for (ItemStack inputStack : input) {
|
||||
FurnaceRecipes.smelting().getSmeltingList().remove(inputStack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding furnace recipe for " + ingredient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing furnace recipe for " + ingredient;
|
||||
}
|
||||
}
|
||||
|
||||
private static class SetFuelAction implements IUndoableAction {
|
||||
private final SetFuelPattern pattern;
|
||||
|
||||
public SetFuelAction(SetFuelPattern pattern) {
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
FuelTweaker.INSTANCE.addFuelPattern(pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
FuelTweaker.INSTANCE.removeFuelPattern(pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Setting fuel for " + pattern.getPattern();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing fuel for " + pattern.getPattern();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package minetweaker.mc164.furnace;
|
||||
|
||||
import minetweaker.api.item.IIngredient;
|
||||
|
||||
public class SetFuelPattern {
|
||||
private final IIngredient pattern;
|
||||
private final int value;
|
||||
|
||||
public SetFuelPattern(IIngredient pattern, int value) {
|
||||
this.pattern = pattern;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public IIngredient getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.item;
|
||||
|
||||
import minetweaker.api.item.IItemDefinition;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCItemDefinition implements IItemDefinition {
|
||||
private final Item item;
|
||||
|
||||
public MCItemDefinition(Item item) {
|
||||
this.item = item;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.item;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.mc164.data.NBTConverter;
|
||||
import minetweaker.mc164.liquid.MCLiquidStack;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemCondition;
|
||||
import minetweaker.api.item.IItemDefinition;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.IItemTransformer;
|
||||
import minetweaker.api.item.IngredientItem;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCItemStack implements IItemStack {
|
||||
private final ItemStack stack;
|
||||
private final List<IItemStack> items;
|
||||
private IData tag = null;
|
||||
private boolean wildcardSize;
|
||||
|
||||
public MCItemStack(ItemStack itemStack) {
|
||||
if (itemStack == null) throw new IllegalArgumentException("stack cannot be null");
|
||||
|
||||
stack = itemStack.copy();
|
||||
items = Collections.<IItemStack>singletonList(this);
|
||||
}
|
||||
|
||||
public MCItemStack(ItemStack itemStack, boolean wildcardSize) {
|
||||
this(itemStack);
|
||||
|
||||
this.wildcardSize = wildcardSize;
|
||||
}
|
||||
|
||||
private MCItemStack(ItemStack itemStack, IData tag) {
|
||||
if (itemStack == null) throw new IllegalArgumentException("stack cannot be null");
|
||||
|
||||
stack = itemStack;
|
||||
items = Collections.<IItemStack>singletonList(this);
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemDefinition getDefinition() {
|
||||
return new MCItemDefinition(stack.getItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return stack.getUnlocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return stack.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDamage() {
|
||||
return stack.getItemDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getTag() {
|
||||
if (tag == null) {
|
||||
if (stack.stackTagCompound == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
tag = NBTConverter.from(stack.stackTagCompound, true);
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxDamage() {
|
||||
return stack.getMaxDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILiquidStack getLiquid() {
|
||||
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(stack);
|
||||
return liquid == null ? null : new MCLiquidStack(liquid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient anyDamage() {
|
||||
if (stack.getItem().getHasSubtypes()) {
|
||||
MineTweakerAPI.logger.logWarning("subitems don't have damaged states");
|
||||
return this;
|
||||
} else {
|
||||
ItemStack result = new ItemStack(stack.getItem(), stack.stackSize, OreDictionary.WILDCARD_VALUE);
|
||||
result.stackTagCompound = stack.stackTagCompound;
|
||||
return new MCItemStack(result, tag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack withDamage(int damage) {
|
||||
if (stack.getItem().getHasSubtypes()) {
|
||||
MineTweakerAPI.logger.logWarning("subitems don't have damaged states");
|
||||
return this;
|
||||
} else {
|
||||
ItemStack result = new ItemStack(stack.getItem(), stack.stackSize, damage);
|
||||
result.stackTagCompound = stack.stackTagCompound;
|
||||
return new MCItemStack(result, tag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack withAmount(int amount) {
|
||||
ItemStack result = new ItemStack(stack.getItem(), amount, stack.getItemDamage());
|
||||
result.stackTagCompound = stack.stackTagCompound;
|
||||
return new MCItemStack(result, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack withTag(IData tag) {
|
||||
ItemStack result = new ItemStack(stack.getItem(), stack.stackSize, stack.getItemDamage());
|
||||
if (tag == null) {
|
||||
result.stackTagCompound = null;
|
||||
} else {
|
||||
result.stackTagCompound = (NBTTagCompound) NBTConverter.from(tag);
|
||||
}
|
||||
return new MCItemStack(result, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack updateTag(IData tagUpdate) {
|
||||
if (tag == null) {
|
||||
if (stack.stackTagCompound == null) {
|
||||
return withTag(tagUpdate);
|
||||
}
|
||||
|
||||
tag = NBTConverter.from(stack.stackTagCompound, true);
|
||||
}
|
||||
|
||||
IData updated = tag.update(tagUpdate);
|
||||
return withTag(updated);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMark() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return stack.stackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack amount(int amount) {
|
||||
return withAmount(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientItem(this, null, ArrayUtil.EMPTY_CONDITIONS, new IItemTransformer[] { transformer });
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientItem(this, null, new IItemCondition[] { condition }, ArrayUtil.EMPTY_TRANSFORMERS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientItem(this, mark, ArrayUtil.EMPTY_CONDITIONS, ArrayUtil.EMPTY_TRANSFORMERS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
ItemStack internal = (ItemStack) item.getInternal();
|
||||
if (internal == null) {
|
||||
throw new RuntimeException("Invalid item: " + item);
|
||||
}
|
||||
|
||||
return internal.getItem() == stack.getItem()
|
||||
&& (wildcardSize || internal.stackSize == stack.stackSize)
|
||||
&& (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE
|
||||
|| stack.getItemDamage() == internal.getItemDamage()
|
||||
|| (!stack.getHasSubtypes() && !stack.getItem().isDamageable()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
List<IItemStack> iitems = ingredient.getItems();
|
||||
if (iitems == null || iitems.size() != 1) return false;
|
||||
return matches(iitems.get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item) {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append('<');
|
||||
result.append(stack.getItem().getUnlocalizedName());
|
||||
|
||||
if (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
||||
result.append(":*");
|
||||
} else if (stack.getItemDamage() > 0) {
|
||||
result.append(':').append(stack.getItemDamage());
|
||||
}
|
||||
result.append('>');
|
||||
|
||||
if (stack.getTagCompound() != null) {
|
||||
result.append(".withTag(");
|
||||
result.append(NBTConverter.from(stack.getTagCompound(), wildcardSize).toString());
|
||||
result.append(")");
|
||||
}
|
||||
|
||||
if (!wildcardSize) {
|
||||
result.append(" * ").append(stack.stackSize);
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
+270
@@ -0,0 +1,270 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.liquid;
|
||||
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.liquid.ILiquidDefinition;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCLiquidDefinition implements ILiquidDefinition {
|
||||
private final Fluid fluid;
|
||||
|
||||
public MCLiquidDefinition(Fluid fluid) {
|
||||
this.fluid = fluid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return fluid.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return fluid.getLocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILiquidStack asStack(int millibuckets) {
|
||||
return new MCLiquidStack(new FluidStack(fluid, millibuckets));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLuminosity() {
|
||||
return fluid.getLuminosity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLuminosity(int value) {
|
||||
MineTweakerAPI.tweaker.apply(new ActionSetLuminosity(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDensity() {
|
||||
return fluid.getDensity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDensity(int density) {
|
||||
MineTweakerAPI.tweaker.apply(new ActionSetDensity(density));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTemperature() {
|
||||
return fluid.getTemperature();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTemperature(int temperature) {
|
||||
MineTweakerAPI.tweaker.apply(new ActionSetTemperature(temperature));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViscosity() {
|
||||
return fluid.getViscosity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setViscosity(int viscosity) {
|
||||
MineTweakerAPI.tweaker.apply(new ActionSetViscosity(viscosity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGaseous() {
|
||||
return fluid.isGaseous();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGaseous(boolean gaseous) {
|
||||
MineTweakerAPI.tweaker.apply(new ActionSetGaseous(gaseous));
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private class ActionSetLuminosity implements IUndoableAction {
|
||||
private final int oldValue;
|
||||
private final int newValue;
|
||||
|
||||
public ActionSetLuminosity(int newValue) {
|
||||
oldValue = getLuminosity();
|
||||
this.newValue = newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
fluid.setLuminosity(newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
fluid.setLuminosity(oldValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Setting " + fluid.getName() + " luminosity to " + newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring " + fluid.getName() + " luminosity to " + oldValue;
|
||||
}
|
||||
}
|
||||
|
||||
private class ActionSetDensity implements IUndoableAction {
|
||||
private final int oldValue;
|
||||
private final int newValue;
|
||||
|
||||
public ActionSetDensity(int newValue) {
|
||||
oldValue = getDensity();
|
||||
this.newValue = newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
fluid.setDensity(newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
fluid.setDensity(oldValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Setting " + fluid.getName() + " density to " + newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring " + fluid.getName() + " density to " + oldValue;
|
||||
}
|
||||
}
|
||||
|
||||
private class ActionSetTemperature implements IUndoableAction {
|
||||
private final int oldValue;
|
||||
private final int newValue;
|
||||
|
||||
public ActionSetTemperature(int newValue) {
|
||||
oldValue = getTemperature();
|
||||
this.newValue = newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
fluid.setTemperature(newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
fluid.setTemperature(oldValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Setting " + fluid.getName() + " temperature to " + newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring " + fluid.getName() + " temperature to " + oldValue;
|
||||
}
|
||||
}
|
||||
|
||||
private class ActionSetViscosity implements IUndoableAction {
|
||||
private final int oldValue;
|
||||
private final int newValue;
|
||||
|
||||
public ActionSetViscosity(int newValue) {
|
||||
oldValue = getViscosity();
|
||||
this.newValue = newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
fluid.setViscosity(newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
fluid.setViscosity(oldValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Setting " + fluid.getName() + " viscosity to " + newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring " + fluid.getName() + " viscosity to " + oldValue;
|
||||
}
|
||||
}
|
||||
|
||||
private class ActionSetGaseous implements IUndoableAction {
|
||||
private final boolean oldValue;
|
||||
private final boolean newValue;
|
||||
|
||||
public ActionSetGaseous(boolean newValue) {
|
||||
oldValue = isGaseous();
|
||||
this.newValue = newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
fluid.setGaseous(newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
fluid.setGaseous(oldValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Setting " + fluid.getName() + " gaseous to " + newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring " + fluid.getName() + " gaseous to " + oldValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.liquid;
|
||||
|
||||
import minetweaker.mc164.data.NBTConverter;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.liquid.ILiquidDefinition;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCLiquidStack implements ILiquidStack {
|
||||
private final FluidStack stack;
|
||||
private IData tag = null;
|
||||
|
||||
public MCLiquidStack(FluidStack stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
private MCLiquidStack(FluidStack stack, IData tag) {
|
||||
this.stack = stack;
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILiquidDefinition getDefinition() {
|
||||
return new MCLiquidDefinition(stack.getFluid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return stack.getFluid().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return stack.getFluid().getLocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return stack.amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getTag() {
|
||||
if (tag == null) {
|
||||
if (stack.tag == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
tag = NBTConverter.from(stack.tag, true);
|
||||
}
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILiquidStack withTag(IData data) {
|
||||
FluidStack result = new FluidStack(stack.fluidID, stack.amount);
|
||||
result.tag = (NBTTagCompound) NBTConverter.from(data);
|
||||
return new MCLiquidStack(result, data.immutable());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILiquidStack withAmount(int amount) {
|
||||
FluidStack result = new FluidStack(stack.fluidID, amount);
|
||||
result.tag = stack.tag;
|
||||
return new MCLiquidStack(result, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLuminosity() {
|
||||
return stack.getFluid().getLuminosity(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDensity() {
|
||||
return stack.getFluid().getDensity(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTemperature() {
|
||||
return stack.getFluid().getTemperature(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViscosity() {
|
||||
return stack.getFluid().getViscosity(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGaseous() {
|
||||
return stack.getFluid().isGaseous(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package minetweaker.mc164.mods;
|
||||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import minetweaker.api.mods.ILoadedMods;
|
||||
import minetweaker.api.mods.IMod;
|
||||
import stanhebben.zenscript.util.MappingIterator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCLoadedMods implements ILoadedMods {
|
||||
public MCLoadedMods() {}
|
||||
|
||||
@Override
|
||||
public boolean contains(String name) {
|
||||
return Loader.isModLoaded(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMod get(String name) {
|
||||
for (ModContainer mod : Loader.instance().getActiveModList()) {
|
||||
if (mod.getModId().equals(name)) {
|
||||
return new MCMod(mod);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IMod> iterator() {
|
||||
List<ModContainer> mods = Loader.instance().getActiveModList();
|
||||
return new MappingIterator<ModContainer, IMod>(mods.iterator()) {
|
||||
@Override
|
||||
public IMod map(ModContainer value) {
|
||||
return new MCMod(value);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.mods;
|
||||
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import minetweaker.api.mods.IMod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCMod implements IMod {
|
||||
private final ModContainer mod;
|
||||
|
||||
public MCMod(ModContainer mod) {
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return mod.getModId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return mod.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return mod.getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return mod.getMetadata().description;
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.network;
|
||||
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.NetLoginHandler;
|
||||
import net.minecraft.network.packet.NetHandler;
|
||||
import net.minecraft.network.packet.Packet1Login;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import cpw.mods.fml.common.network.IConnectionHandler;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
|
||||
public class MCConnectionHandler implements IConnectionHandler {
|
||||
@Override
|
||||
public void playerLoggedIn(Player player, NetHandler netHandler,
|
||||
INetworkManager manager) {
|
||||
/*String[] admins = MineTweaker.instance.getAdmins();
|
||||
boolean canSendErrors = false;
|
||||
if (admins.length == 0) {
|
||||
canSendErrors = true;
|
||||
} else {
|
||||
for (String s : admins) {
|
||||
if (s.equals(netHandler.getPlayer().getEntityName())) canSendErrors = true;
|
||||
}
|
||||
}
|
||||
if (canSendErrors) {
|
||||
for (String s : MineTweaker.instance.getErrorMessages()) {
|
||||
//#ifdef MC152
|
||||
//+netHandler.getPlayer().sendChatToPlayer(s);
|
||||
//#else
|
||||
netHandler.getPlayer().sendChatToPlayer(ChatMessageComponent.createFromText(s));
|
||||
//#endif
|
||||
}
|
||||
MineTweaker.instance.onAdminLogin(manager, netHandler);
|
||||
}*/
|
||||
manager.addToSendQueue(new Packet250CustomPayload(
|
||||
MCPacketHandler.CHANNEL_SERVERSCRIPT,
|
||||
MineTweakerAPI.tweaker.getScriptData()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String connectionReceived(NetLoginHandler netHandler,
|
||||
INetworkManager manager) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionOpened(NetHandler netClientHandler, String server,
|
||||
int port, INetworkManager manager) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionOpened(NetHandler netClientHandler,
|
||||
MinecraftServer server, INetworkManager manager) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionClosed(INetworkManager manager) {
|
||||
//MineTweaker.instance.onLogout(manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clientLoggedIn(NetHandler clientHandler,
|
||||
INetworkManager manager, Packet1Login login) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.network;
|
||||
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import cpw.mods.fml.common.network.IPacketHandler;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.runtime.providers.ScriptProviderMemory;
|
||||
|
||||
public class MCPacketHandler implements IPacketHandler {
|
||||
public static final String CHANNEL_SERVERSCRIPT = "MTServerScript";
|
||||
|
||||
@Override
|
||||
public void onPacketData(INetworkManager manager,
|
||||
Packet250CustomPayload packet, Player player) {
|
||||
// catches some special cases caused by unknown reasons
|
||||
if (packet == null || packet.channel == null || packet.data == null) return;
|
||||
|
||||
if (packet.channel.equals(CHANNEL_SERVERSCRIPT)) {
|
||||
MineTweakerAPI.tweaker.setScriptProvider(new ScriptProviderMemory(packet.data));
|
||||
MineTweakerAPI.tweaker.rollback();
|
||||
MineTweakerAPI.tweaker.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.oredict;
|
||||
|
||||
import minetweaker.api.oredict.IOreDict;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCOreDict implements IOreDict {
|
||||
@Override
|
||||
public IOreDictEntry get(String name) {
|
||||
return new MCOreDictEntry(OreDictionary.getOreID(name));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.oredict;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.mc164.item.MCItemStack;
|
||||
import minetweaker.mc164.util.MineTweakerHacks;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemCondition;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.IItemTransformer;
|
||||
import minetweaker.api.item.IngredientStack;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import minetweaker.api.oredict.IngredientOreDict;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCOreDictEntry implements IOreDictEntry {
|
||||
private final Integer id;
|
||||
|
||||
public MCOreDictEntry(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public MCOreDictEntry(String id) {
|
||||
this.id = OreDictionary.getOreID(id);
|
||||
}
|
||||
|
||||
// ####################################
|
||||
// ### IOreDictEntry implementation ###
|
||||
// ####################################
|
||||
|
||||
@Override
|
||||
public void add(IItemStack item) {
|
||||
ItemStack stack = (ItemStack) item.getInternal();
|
||||
if (stack == null) {
|
||||
MineTweakerAPI.logger.logError("not a valid item");
|
||||
} else {
|
||||
MineTweakerAPI.tweaker.apply(new ActionAddItem(id, stack));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAll(IOreDictEntry entry) {
|
||||
if (entry instanceof MCOreDictEntry) {
|
||||
MineTweakerAPI.tweaker.apply(new ActionAddAll(id, ((MCOreDictEntry) entry).id));
|
||||
} else {
|
||||
MineTweakerAPI.logger.logError("not a valid entry");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(IItemStack item) {
|
||||
ItemStack result = null;
|
||||
for (ItemStack itemStack : OreDictionary.getOres(id)) {
|
||||
if (item.matches(new MCItemStack(itemStack))) {
|
||||
result = itemStack;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (result != null) {
|
||||
MineTweakerAPI.tweaker.apply(new ActionRemoveItem(id, result));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IItemStack item) {
|
||||
for (ItemStack itemStack : OreDictionary.getOres(id)) {
|
||||
if (item.matches(new MCItemStack(itemStack))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mirror(IOreDictEntry other) {
|
||||
if (other instanceof MCOreDictEntry) {
|
||||
MineTweakerAPI.tweaker.apply(new ActionMirror(id, ((MCOreDictEntry) other).id));
|
||||
} else {
|
||||
MineTweakerAPI.logger.logError("not a valid oredict entry");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMark() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
List<IItemStack> result = new ArrayList<IItemStack>();
|
||||
for (ItemStack item : OreDictionary.getOres(id)) {
|
||||
result.add(new MCItemStack(item));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
return new IngredientStack(this, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientOreDict(this, null, ArrayUtil.EMPTY_CONDITIONS, new IItemTransformer[] { transformer });
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientOreDict(this, null, new IItemCondition[] { condition }, ArrayUtil.EMPTY_TRANSFORMERS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientOreDict(this, mark, ArrayUtil.EMPTY_CONDITIONS, ArrayUtil.EMPTY_TRANSFORMERS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
return contains(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
List<IItemStack> items = ingredient.getItems();
|
||||
for (IItemStack item : items) {
|
||||
if (!matches(item)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item) {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return OreDictionary.getOreName(id);
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private static class ActionAddItem implements IUndoableAction {
|
||||
private final Integer id;
|
||||
private final ItemStack item;
|
||||
|
||||
public ActionAddItem(Integer id, ItemStack item) {
|
||||
this.id = id;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
OreDictionary.registerOre(id, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
OreDictionary.getOres(id).remove(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding " + item.getDisplayName() + " to ore dictionary entry " + OreDictionary.getOreName(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing " + item.getDisplayName() + " from ore dictionary entry " + OreDictionary.getOreName(id);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ActionMirror implements IUndoableAction {
|
||||
private final Integer idTarget;
|
||||
private final Integer idSource;
|
||||
|
||||
private final ArrayList<ItemStack> targetCopy;
|
||||
|
||||
public ActionMirror(Integer idTarget, Integer idSource) {
|
||||
this.idTarget = idTarget;
|
||||
this.idSource = idSource;
|
||||
|
||||
targetCopy = OreDictionary.getOres(idTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
MineTweakerHacks.getOreStacks().put(idTarget, OreDictionary.getOres(idSource));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
MineTweakerHacks.getOreStacks().put(idTarget, targetCopy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Mirroring " + OreDictionary.getOreName(idSource) + " to " + OreDictionary.getOreName(idTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Undoing mirror of " + OreDictionary.getOreName(idSource) + " to " + OreDictionary.getOreName(idTarget);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ActionRemoveItem implements IUndoableAction {
|
||||
private final Integer id;
|
||||
private final ItemStack item;
|
||||
|
||||
public ActionRemoveItem(Integer id, ItemStack item) {
|
||||
this.id = id;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
OreDictionary.getOres(id).remove(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
OreDictionary.getOres(id).add(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing " + item.getDisplayName() + " from ore dictionary entry " + OreDictionary.getOreName(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring " + item.getDisplayName() + " to ore dictionary entry " + OreDictionary.getOreName(id);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ActionAddAll implements IUndoableAction {
|
||||
private final Integer idTarget;
|
||||
private final Integer idSource;
|
||||
|
||||
public ActionAddAll(Integer idTarget, Integer idSource) {
|
||||
this.idTarget = idTarget;
|
||||
this.idSource = idSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
List<ItemStack> ores = OreDictionary.getOres(idTarget);
|
||||
for (ItemStack stack : OreDictionary.getOres(idSource)) {
|
||||
ores.add(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
List<ItemStack> ores = OreDictionary.getOres(idTarget);
|
||||
for (ItemStack stack : OreDictionary.getOres(idSource)) {
|
||||
ores.remove(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Copying contents of ore dictionary entry " + OreDictionary.getOreName(idSource) + " to " + OreDictionary.getOreName(idTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing contents of ore dictionary entry " + OreDictionary.getOreName(idSource) + " from " + OreDictionary.getOreName(idTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.player;
|
||||
|
||||
import minetweaker.mc164.data.NBTConverter;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCPlayer implements IPlayer {
|
||||
private final EntityPlayer player;
|
||||
|
||||
public MCPlayer(EntityPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return player.getCommandSenderName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getData() {
|
||||
return NBTConverter.from(player.getEntityData(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(IData data) {
|
||||
NBTConverter.updateMap(player.getEntityData(), data);
|
||||
}
|
||||
}
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.recipes;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.mc164.item.MCItemStack;
|
||||
import minetweaker.mc164.util.MineTweakerHacks;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.recipes.ICraftingInventory;
|
||||
import minetweaker.mc164.player.MCPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.inventory.SlotCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCCraftingInventory implements ICraftingInventory {
|
||||
private static final ThreadLocal<MCCraftingInventory> cache = new ThreadLocal<MCCraftingInventory>();
|
||||
|
||||
public static MCCraftingInventory get(InventoryCrafting inventory) {
|
||||
if (cache.get() == null || cache.get().inventory != inventory) {
|
||||
MCCraftingInventory result = new MCCraftingInventory(inventory);
|
||||
cache.set(result);
|
||||
return result;
|
||||
} else {
|
||||
MCCraftingInventory result = cache.get();
|
||||
result.update();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private int width;
|
||||
private int height;
|
||||
private final InventoryCrafting inventory;
|
||||
private IItemStack[] stacks;
|
||||
private ItemStack[] original;
|
||||
private int stackCount;
|
||||
private MCPlayer player;
|
||||
|
||||
private MCCraftingInventory(InventoryCrafting inventory) {
|
||||
this.inventory = inventory;
|
||||
width = height = (int) Math.sqrt(inventory.getSizeInventory());
|
||||
stacks = new IItemStack[width * height];
|
||||
original = new ItemStack[stacks.length];
|
||||
stackCount = 0;
|
||||
update();
|
||||
|
||||
Container container = MineTweakerHacks.getCraftingContainer(inventory);
|
||||
List<Slot> slots = container.inventorySlots;
|
||||
if (!slots.isEmpty() && slots.get(0) instanceof SlotCrafting) {
|
||||
SlotCrafting slotCrafting = (SlotCrafting) slots.get(0);
|
||||
EntityPlayer playerEntity = MineTweakerHacks.getCraftingSlotPlayer(slotCrafting);
|
||||
player = new MCPlayer(playerEntity);
|
||||
} else {
|
||||
player = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void update() {
|
||||
if (inventory.getSizeInventory() != original.length) {
|
||||
width = height = (int) Math.sqrt(inventory.getSizeInventory());
|
||||
stacks = new IItemStack[inventory.getSizeInventory()];
|
||||
original = new ItemStack[stacks.length];
|
||||
stackCount = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
||||
if (changed(i)) {
|
||||
//System.out.println("Slot " + i + " changed");
|
||||
original[i] = inventory.getStackInSlot(i);
|
||||
if (inventory.getStackInSlot(i) != null) {
|
||||
if (stacks[i] == null) stackCount++;
|
||||
stacks[i] = new MCItemStack(original[i]);
|
||||
} else {
|
||||
if (stacks[i] != null) stackCount--;
|
||||
stacks[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
//System.out.println("Num stack count: " + stackCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return width * height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStackCount() {
|
||||
return stackCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getStack(int i) {
|
||||
return stacks[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getStack(int x, int y) {
|
||||
return stacks[y * width + x];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStack(int x, int y, IItemStack stack) {
|
||||
//System.out.println("SetStack(" + x + ", " + y + ") " + stack);
|
||||
|
||||
int ix = y * width + x;
|
||||
if (stack != stacks[ix]) {
|
||||
if (stack == null) {
|
||||
stackCount--;
|
||||
inventory.setInventorySlotContents(ix, null);
|
||||
} else {
|
||||
inventory.setInventorySlotContents(ix, (ItemStack) stack.getInternal());
|
||||
|
||||
if (stacks[ix] == null) {
|
||||
stackCount++;
|
||||
}
|
||||
}
|
||||
stacks[ix] = stack;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStack(int i, IItemStack stack) {
|
||||
//System.out.println("SetStack(" + i + ") " + stack);
|
||||
|
||||
if (stack != stacks[i]) {
|
||||
if (stack == null) {
|
||||
stackCount--;
|
||||
inventory.setInventorySlotContents(i, null);
|
||||
} else {
|
||||
inventory.setInventorySlotContents(i, (ItemStack) stack.getInternal());
|
||||
|
||||
if (stacks[i] == null) {
|
||||
stackCount++;
|
||||
}
|
||||
}
|
||||
stacks[i] = stack;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean changed(int i) {
|
||||
if (original[i] != inventory.getStackInSlot(i)) return true;
|
||||
if (original[i] != null && stacks[i].getAmount() != original[i].stackSize) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,358 @@
|
||||
package minetweaker.mc164.recipes;
|
||||
|
||||
import minetweaker.api.recipes.ShapedRecipe;
|
||||
import minetweaker.api.recipes.ShapelessRecipe;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.mc164.item.MCItemStack;
|
||||
import minetweaker.mc164.oredict.MCOreDictEntry;
|
||||
import minetweaker.mc164.util.MineTweakerHacks;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.recipes.IRecipeFunction;
|
||||
import minetweaker.api.recipes.IRecipeManager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.ShapedRecipes;
|
||||
import net.minecraft.item.crafting.ShapelessRecipes;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCRecipeManager implements IRecipeManager {
|
||||
private final List<IRecipe> recipes;
|
||||
|
||||
public MCRecipeManager() {
|
||||
recipes = (List<IRecipe>) CraftingManager.getInstance().getRecipeList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int remove(IIngredient output) {
|
||||
List<IRecipe> toRemove = new ArrayList<IRecipe>();
|
||||
List<Integer> removeIndex = new ArrayList<Integer>();
|
||||
for (int i = 0; i < recipes.size(); i++) {
|
||||
IRecipe recipe = recipes.get(i);
|
||||
|
||||
// certain special recipes have no predefined output. ignore those
|
||||
// since these cannot be removed with MineTweaker scripts
|
||||
if (recipe.getRecipeOutput() != null) {
|
||||
if (output.matches(new MCItemStack(recipe.getRecipeOutput()))) {
|
||||
toRemove.add(recipe);
|
||||
removeIndex.add(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MineTweakerAPI.tweaker.apply(new ActionRemoveRecipes(toRemove, removeIndex));
|
||||
return toRemove.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, boolean mirrored) {
|
||||
if (output.getInternal() == null) {
|
||||
MineTweakerAPI.logger.logError("invalid output item");
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = new ShapedRecipe(output, ingredients, function, mirrored);
|
||||
IRecipe irecipe = RecipeConverter.convert(recipe);
|
||||
MineTweakerAPI.tweaker.apply(new ActionAddRecipe(irecipe));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addShapeless(IItemStack output, IIngredient[] ingredients, IRecipeFunction function) {
|
||||
if (output.getInternal() == null) {
|
||||
MineTweakerAPI.logger.logError("invalid output item");
|
||||
return;
|
||||
}
|
||||
|
||||
ShapelessRecipe recipe = new ShapelessRecipe(output, ingredients, function);
|
||||
IRecipe irecipe = RecipeConverter.convert(recipe);
|
||||
MineTweakerAPI.tweaker.apply(new ActionAddRecipe(irecipe));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int removeShaped(IIngredient output, IIngredient[][] ingredients) {
|
||||
int ingredientsWidth = 0;
|
||||
int ingredientsHeight = 0;
|
||||
|
||||
if (ingredients != null) {
|
||||
ingredientsHeight = ingredients.length;
|
||||
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
ingredientsWidth = Math.max(ingredientsWidth, ingredients[i].length);
|
||||
}
|
||||
}
|
||||
|
||||
List<IRecipe> toRemove = new ArrayList<IRecipe>();
|
||||
List<Integer> removeIndex = new ArrayList<Integer>();
|
||||
outer: for (int i = 0; i < recipes.size(); i++) {
|
||||
IRecipe recipe = recipes.get(i);
|
||||
|
||||
if (recipe.getRecipeOutput() == null || !output.matches(new MCItemStack(recipe.getRecipeOutput()))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ingredients != null) {
|
||||
if (recipe instanceof ShapedRecipes) {
|
||||
ShapedRecipes srecipe = (ShapedRecipes) recipe;
|
||||
if (ingredientsWidth != srecipe.recipeWidth || ingredientsHeight != srecipe.recipeHeight) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 0; j < ingredientsHeight; j++) {
|
||||
IIngredient[] row = ingredients[j];
|
||||
for (int k = 0; k < ingredientsWidth; k++) {
|
||||
IIngredient ingredient = k > row.length ? null : row[k];
|
||||
ItemStack recipeIngredient = srecipe.recipeItems[j * srecipe.recipeWidth + k];
|
||||
|
||||
if (!matches(recipeIngredient, ingredient)) {
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (recipe instanceof ShapedOreRecipe) {
|
||||
ShapedOreRecipe srecipe = (ShapedOreRecipe) recipe;
|
||||
int recipeWidth = MineTweakerHacks.getShapedOreRecipeWidth(srecipe);
|
||||
int recipeHeight = srecipe.getRecipeSize() / recipeWidth;
|
||||
if (ingredientsWidth != recipeWidth || ingredientsHeight != recipeHeight) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 0; j < ingredientsHeight; j++) {
|
||||
IIngredient[] row = ingredients[j];
|
||||
for (int k = 0; k < ingredientsWidth; k++) {
|
||||
IIngredient ingredient = k > row.length ? null : row[k];
|
||||
Object input = srecipe.getInput()[j * recipeWidth + k];
|
||||
if (!matches(input, ingredient)) {
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (recipe instanceof ShapedRecipe) {
|
||||
|
||||
} else if (recipe instanceof ShapedOreRecipe) {
|
||||
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
toRemove.add(recipe);
|
||||
removeIndex.add(i);
|
||||
}
|
||||
|
||||
MineTweakerAPI.tweaker.apply(new ActionRemoveRecipes(toRemove, removeIndex));
|
||||
return toRemove.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int removeShapeless(IIngredient output, IIngredient[] ingredients, boolean wildcard) {
|
||||
List<IRecipe> toRemove = new ArrayList<IRecipe>();
|
||||
List<Integer> removeIndex = new ArrayList<Integer>();
|
||||
outer: for (int i = 0; i < recipes.size(); i++) {
|
||||
IRecipe recipe = recipes.get(i);
|
||||
|
||||
if (recipe.getRecipeOutput() == null || !output.matches(new MCItemStack(recipe.getRecipeOutput()))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ingredients != null) {
|
||||
if (recipe instanceof ShapelessRecipes) {
|
||||
ShapelessRecipes srecipe = (ShapelessRecipes) recipe;
|
||||
|
||||
if (ingredients.length > srecipe.getRecipeSize()) {
|
||||
continue;
|
||||
} else if (!wildcard && ingredients.length < srecipe.getRecipeSize()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
checkIngredient: for (int j = 0; j < ingredients.length; j++) {
|
||||
for (int k = 0; k < srecipe.getRecipeSize(); k++) {
|
||||
if (matches(srecipe.recipeItems.get(k), ingredients[j])) {
|
||||
continue checkIngredient;
|
||||
}
|
||||
}
|
||||
|
||||
continue outer;
|
||||
}
|
||||
} else if (recipe instanceof ShapelessOreRecipe) {
|
||||
ShapelessOreRecipe srecipe = (ShapelessOreRecipe) recipe;
|
||||
ArrayList<Object> inputs = srecipe.getInput();
|
||||
|
||||
if (inputs.size() < ingredients.length) {
|
||||
continue;
|
||||
} if (!wildcard && inputs.size() > ingredients.length) {
|
||||
continue;
|
||||
}
|
||||
|
||||
checkIngredient: for (int j = 0; j < ingredients.length; j++) {
|
||||
for (int k = 0; k < srecipe.getRecipeSize(); k++) {
|
||||
if (matches(inputs.get(k), ingredients[j])) {
|
||||
continue checkIngredient;
|
||||
}
|
||||
}
|
||||
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (recipe instanceof ShapelessRecipes) {
|
||||
|
||||
} else if (recipe instanceof ShapelessOreRecipe) {
|
||||
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
toRemove.add(recipe);
|
||||
removeIndex.add(i);
|
||||
}
|
||||
|
||||
MineTweakerAPI.tweaker.apply(new ActionRemoveRecipes(toRemove, removeIndex));
|
||||
return toRemove.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack craft(IItemStack[][] contents) {
|
||||
Container container = new ContainerVirtual();
|
||||
|
||||
int width = 0;
|
||||
int height = contents.length;
|
||||
for (IItemStack[] row : contents) {
|
||||
width = Math.max(width, row.length);
|
||||
}
|
||||
|
||||
ItemStack[] iContents = new ItemStack[width * height];
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < contents[i].length; j++) {
|
||||
if (contents[i][j] != null) {
|
||||
Object internal = contents[i][j].getInternal();
|
||||
if (internal != null && (internal instanceof ItemStack)) {
|
||||
iContents[i * width + j] = (ItemStack) internal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InventoryCrafting inventory = new InventoryCrafting(container, width, height);
|
||||
for (int i = 0; i < iContents.length; i++) {
|
||||
inventory.setInventorySlotContents(i, iContents[i]);
|
||||
}
|
||||
ItemStack result = CraftingManager.getInstance().findMatchingRecipe(inventory, null);
|
||||
if (result == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new MCItemStack(result);
|
||||
}
|
||||
}
|
||||
|
||||
private class ContainerVirtual extends Container {
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer var1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private class ActionRemoveRecipes implements IUndoableAction {
|
||||
private final List<Integer> removingIndices;
|
||||
private final List<IRecipe> removingRecipes;
|
||||
|
||||
public ActionRemoveRecipes(List<IRecipe> recipes, List<Integer> indices) {
|
||||
this.removingIndices = indices;
|
||||
this.removingRecipes = recipes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (int i = removingIndices.size() - 1; i >= 0; i--) {
|
||||
recipes.remove((int) removingIndices.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
for (int i = 0; i < removingIndices.size(); i++) {
|
||||
recipes.add(removingIndices.get(i), removingRecipes.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing " + removingIndices.size() + " recipes";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring " + removingIndices.size() + " recipes";
|
||||
}
|
||||
}
|
||||
|
||||
private class ActionAddRecipe implements IUndoableAction {
|
||||
private final IRecipe recipe;
|
||||
|
||||
public ActionAddRecipe(IRecipe recipe) {
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
recipes.remove(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding recipe for " + recipe.getRecipeOutput().getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing recipe for " + recipe.getRecipeOutput().getDisplayName();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean matches(Object input, IIngredient ingredient) {
|
||||
if ((input == null) != (ingredient == null)) {
|
||||
return false;
|
||||
} else if (ingredient != null) {
|
||||
if (input instanceof ItemStack) {
|
||||
if (!ingredient.matches(new MCItemStack((ItemStack) input))) {
|
||||
return false;
|
||||
}
|
||||
} else if (input instanceof String) {
|
||||
if (!ingredient.contains(new MCOreDictEntry((String) input))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.recipes;
|
||||
|
||||
import minetweaker.api.recipes.ShapedRecipe;
|
||||
import minetweaker.api.recipes.ShapelessRecipe;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class RecipeConverter {
|
||||
private RecipeConverter() {}
|
||||
|
||||
public static final int TYPE_ADVANCED = 0;
|
||||
public static final int TYPE_ORE = 1;
|
||||
public static final int TYPE_BASIC = 2;
|
||||
|
||||
private static int getIngredientType(IIngredient pattern) {
|
||||
Object internal = pattern.getInternal();
|
||||
if (internal == null) {
|
||||
return TYPE_ADVANCED;
|
||||
} else if (internal instanceof ItemStack) {
|
||||
return TYPE_BASIC;
|
||||
} else {
|
||||
return TYPE_ORE;
|
||||
}
|
||||
}
|
||||
|
||||
private static int getRecipeType(IIngredient[] ingredients) {
|
||||
int type = TYPE_BASIC;
|
||||
for (IIngredient ingredient : ingredients) {
|
||||
type = Math.min(type, getIngredientType(ingredient));
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
public static IRecipe convert(ShapelessRecipe recipe) {
|
||||
IIngredient[] ingredients = recipe.getIngredients();
|
||||
int type = getRecipeType(ingredients);
|
||||
|
||||
if (type == TYPE_BASIC) {
|
||||
ItemStack[] items = new ItemStack[ingredients.length];
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
items[i] = (ItemStack) ingredients[i].getInternal();
|
||||
}
|
||||
return new ShapelessRecipeBasic(items, recipe);
|
||||
} else if (type == TYPE_ORE) {
|
||||
Object[] items = new Object[ingredients.length];
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
items[i] = ingredients[i].getInternal();
|
||||
}
|
||||
return new ShapelessRecipeOre(items, recipe);
|
||||
} else {
|
||||
return new ShapelessRecipeAdvanced(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
public static IRecipe convert(ShapedRecipe recipe) {
|
||||
IIngredient[] ingredients = recipe.getIngredients();
|
||||
byte[] posx = recipe.getIngredientsX();
|
||||
byte[] posy = recipe.getIngredientsY();
|
||||
|
||||
// determine recipe type
|
||||
int type = getRecipeType(ingredients);
|
||||
|
||||
// construct recipe
|
||||
if (type == TYPE_BASIC) {
|
||||
System.out.println("Converted to basic recipe");
|
||||
ItemStack[] basicIngredients = new ItemStack[recipe.getHeight() * recipe.getWidth()];
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
basicIngredients[posx[i] + posy[i] * recipe.getWidth()] = (ItemStack) ingredients[i].getInternal();
|
||||
}
|
||||
|
||||
return new ShapedRecipeBasic(basicIngredients, recipe);
|
||||
} else if (type == TYPE_ORE) {
|
||||
System.out.println("Converted to ore recipe");
|
||||
Object[] converted = new Object[recipe.getHeight() * recipe.getWidth()];
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
converted[posx[i] + posy[i] * recipe.getWidth()] = ingredients[i].getInternal();
|
||||
}
|
||||
|
||||
// arguments contents:
|
||||
// 1) recipe patterns
|
||||
// 2) characters + ingredients
|
||||
|
||||
int counter = 0;
|
||||
String[] parts = new String[recipe.getHeight()];
|
||||
ArrayList rarguments = new ArrayList();
|
||||
for (int i = 0; i < recipe.getHeight(); i++) {
|
||||
char[] pattern = new char[recipe.getWidth()];
|
||||
for (int j = 0; j < recipe.getWidth(); j++) {
|
||||
int off = i * recipe.getWidth() + j;
|
||||
if (converted[off] == null) {
|
||||
pattern[j] = ' ';
|
||||
} else {
|
||||
pattern[j] = (char) ('A' + counter);
|
||||
rarguments.add(pattern[j]);
|
||||
rarguments.add(converted[off]);
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
parts[i] = new String(pattern);
|
||||
}
|
||||
|
||||
rarguments.addAll(0, Arrays.asList(parts));
|
||||
|
||||
return new ShapedRecipeOre(rarguments.toArray(), recipe);
|
||||
} else {
|
||||
System.out.println("Converted to advanced recipe");
|
||||
return new ShapedRecipeAdvanced(recipe);
|
||||
}
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.recipes;
|
||||
|
||||
import minetweaker.api.recipes.ShapedRecipe;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* TODO: NEI integration for this kind of recipes.
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ShapedRecipeAdvanced implements IRecipe {
|
||||
private final ShapedRecipe recipe;
|
||||
|
||||
public ShapedRecipeAdvanced(ShapedRecipe recipe) {
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(InventoryCrafting inventory, World world) {
|
||||
return recipe.matches(MCCraftingInventory.get(inventory));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
||||
return ((ItemStack) recipe.getCraftingResult(MCCraftingInventory.get(inventory)).getInternal()).copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRecipeSize() {
|
||||
return recipe.getWidth() * recipe.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getRecipeOutput() {
|
||||
return (ItemStack) recipe.getOutput().getInternal();
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.recipes;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.recipes.ShapedRecipe;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.ShapedRecipes;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ShapedRecipeBasic extends ShapedRecipes {
|
||||
private final ShapedRecipe recipe;
|
||||
|
||||
public ShapedRecipeBasic(ItemStack[] basicInputs, ShapedRecipe recipe) {
|
||||
super(recipe.getWidth(), recipe.getHeight(), basicInputs, (ItemStack) recipe.getOutput().getInternal());
|
||||
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(InventoryCrafting inventory, World world) {
|
||||
return recipe.matches(MCCraftingInventory.get(inventory));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
||||
IItemStack result = recipe.getCraftingResult(MCCraftingInventory.get(inventory));
|
||||
if (result == null) {
|
||||
return null;
|
||||
} else {
|
||||
return ((ItemStack) result.getInternal()).copy();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.recipes;
|
||||
|
||||
import minetweaker.api.recipes.ShapedRecipe;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ShapedRecipeOre extends ShapedOreRecipe {
|
||||
private final ShapedRecipe recipe;
|
||||
|
||||
public ShapedRecipeOre(Object[] contents, ShapedRecipe recipe) {
|
||||
super((ItemStack) recipe.getOutput().getInternal(), contents);
|
||||
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(InventoryCrafting inventory, World world) {
|
||||
return recipe.matches(MCCraftingInventory.get(inventory));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
||||
return ((ItemStack) recipe.getCraftingResult(MCCraftingInventory.get(inventory)).getInternal()).copy();
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.recipes;
|
||||
|
||||
import minetweaker.api.recipes.ShapelessRecipe;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ShapelessRecipeAdvanced implements IRecipe {
|
||||
private final ShapelessRecipe recipe;
|
||||
|
||||
public ShapelessRecipeAdvanced(ShapelessRecipe recipe) {
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(InventoryCrafting inventory, World world) {
|
||||
return recipe.matches(MCCraftingInventory.get(inventory));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
||||
return ((ItemStack) recipe.getCraftingResult(MCCraftingInventory.get(inventory)).getInternal()).copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRecipeSize() {
|
||||
return recipe.getSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getRecipeOutput() {
|
||||
return (ItemStack) recipe.getOutput().getInternal();
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.recipes;
|
||||
|
||||
import minetweaker.api.recipes.ShapelessRecipe;
|
||||
import java.util.Arrays;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.ShapelessRecipes;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ShapelessRecipeBasic extends ShapelessRecipes {
|
||||
private final ShapelessRecipe recipe;
|
||||
|
||||
public ShapelessRecipeBasic(ItemStack[] ingredients, ShapelessRecipe recipe) {
|
||||
super((ItemStack) recipe.getOutput().getInternal(), Arrays.asList(ingredients));
|
||||
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(InventoryCrafting inventory, World world) {
|
||||
return recipe.matches(MCCraftingInventory.get(inventory));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
||||
return ((ItemStack) recipe.getCraftingResult(MCCraftingInventory.get(inventory)).getInternal()).copy();
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.recipes;
|
||||
|
||||
import minetweaker.api.recipes.ShapelessRecipe;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ShapelessRecipeOre extends ShapelessOreRecipe {
|
||||
private final ShapelessRecipe recipe;
|
||||
|
||||
public ShapelessRecipeOre(Object[] ingredients, ShapelessRecipe recipe) {
|
||||
super((ItemStack) recipe.getOutput().getInternal(), ingredients);
|
||||
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(InventoryCrafting inventory, World world) {
|
||||
return recipe.matches(MCCraftingInventory.get(inventory));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
||||
return ((ItemStack) recipe.getCraftingResult(MCCraftingInventory.get(inventory)).getInternal()).copy();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.inventory.SlotCrafting;import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
|
||||
/**
|
||||
* Common class for all runtime hacks (stuff requiring reflection). It is not
|
||||
* unexpected to have it break with new minecraft versions and may need regular
|
||||
* adjustment - as such, those have been collected here.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class MineTweakerHacks {
|
||||
private static final Field NBTTAGCOMPOUND_TAGMAP;
|
||||
private static final Field OREDICTIONARY_ORESTACKS;
|
||||
private static final Field MINECRAFTSERVER_ANVILFILE;
|
||||
private static final Field SHAPEDORERECIPE_WIDTH;
|
||||
|
||||
private static final Field INVENTORYCRAFTING_EVENTHANDLER;
|
||||
private static final Field SLOTCRAFTING_PLAYER;
|
||||
|
||||
static {
|
||||
NBTTAGCOMPOUND_TAGMAP = getField(NBTTagCompound.class, MineTweakerObfuscation.NBTTAGCOMPOUND_TAGMAP);
|
||||
OREDICTIONARY_ORESTACKS = getField(OreDictionary.class, MineTweakerObfuscation.OREDICTIONARY_ORESTACKS);
|
||||
MINECRAFTSERVER_ANVILFILE = getField(MinecraftServer.class, MineTweakerObfuscation.MINECRAFTSERVER_ANVILFILE);
|
||||
SHAPEDORERECIPE_WIDTH = getField(ShapedOreRecipe.class, new String[] {"width"});
|
||||
|
||||
INVENTORYCRAFTING_EVENTHANDLER = getField(InventoryCrafting.class, MineTweakerObfuscation.INVENTORYCRAFTING_EVENTHANDLER);
|
||||
SLOTCRAFTING_PLAYER = getField(SlotCrafting.class, MineTweakerObfuscation.SLOTCRAFTING_PLAYER);
|
||||
}
|
||||
|
||||
private MineTweakerHacks() {}
|
||||
|
||||
public static Map<String, NBTBase> getNBTCompoundMap(NBTTagCompound tag) {
|
||||
try {
|
||||
return (Map<String, NBTBase>) NBTTAGCOMPOUND_TAGMAP.get(tag);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
return null;
|
||||
} catch (IllegalAccessException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<Integer, List<ItemStack>> getOreStacks() {
|
||||
try {
|
||||
return (Map<Integer, List<ItemStack>>) OREDICTIONARY_ORESTACKS.get(null);
|
||||
} catch (IllegalAccessException ex) {
|
||||
MineTweakerAPI.logger.logError("ERROR - could not load ore dictionary stacks!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static File getAnvilFile(MinecraftServer server) {
|
||||
try {
|
||||
return (File) MINECRAFTSERVER_ANVILFILE.get(server);
|
||||
} catch (IllegalAccessException ex) {
|
||||
MineTweakerAPI.logger.logError("could not load anvil file!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static File getWorldDirectory(MinecraftServer server) {
|
||||
if (server.isDedicatedServer()) {
|
||||
return server.getFile("world");
|
||||
} else {
|
||||
File worldsDir = getAnvilFile(server);
|
||||
if (worldsDir == null) return null;
|
||||
|
||||
return new File(worldsDir, server.getFolderName());
|
||||
}
|
||||
}
|
||||
|
||||
public static int getShapedOreRecipeWidth(ShapedOreRecipe recipe) {
|
||||
try {
|
||||
return SHAPEDORERECIPE_WIDTH.getInt(recipe);
|
||||
} catch (IllegalAccessException ex) {
|
||||
MineTweakerAPI.logger.logError("could not load anvil file!");
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
public static Container getCraftingContainer(InventoryCrafting inventory) {
|
||||
try {
|
||||
return (Container) INVENTORYCRAFTING_EVENTHANDLER.get(inventory);
|
||||
} catch (IllegalAccessException ex) {
|
||||
MineTweakerAPI.logger.logError("could not get inventory eventhandler");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static EntityPlayer getCraftingSlotPlayer(SlotCrafting slot) {
|
||||
try {
|
||||
return (EntityPlayer) SLOTCRAFTING_PLAYER.get(slot);
|
||||
} catch (IllegalAccessException ex) {
|
||||
MineTweakerAPI.logger.logError("could not get inventory eventhandler");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// #######################
|
||||
// ### Private Methods ###
|
||||
// #######################
|
||||
|
||||
private static Field getField(Class cls, String[] names) {
|
||||
for (String name : names) {
|
||||
try {
|
||||
Field field = cls.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
} catch (NoSuchFieldException ex) {
|
||||
} catch (SecurityException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.util;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stanneke
|
||||
*/
|
||||
public class MineTweakerObfuscation {
|
||||
private MineTweakerObfuscation() {}
|
||||
|
||||
public static final String[] NBTTAGCOMPOUND_TAGMAP = {"tagMap", "field_74784_a"};
|
||||
public static final String[] OREDICTIONARY_ORESTACKS = {"oreStacks"};
|
||||
public static final String[] MINECRAFTSERVER_ANVILFILE = {"anvilFile", "field_71308_o"};
|
||||
public static final String[] INVENTORYCRAFTING_EVENTHANDLER = {"eventHandler", "field_70465_c"};
|
||||
public static final String[] SLOTCRAFTING_PLAYER = {"thePlayer", "field_75238_b"};
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.util;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.mc164.item.MCItemStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MineTweakerUtil {
|
||||
public static ItemStack[] getItemStacks(IItemStack... items) {
|
||||
ItemStack[] output = new ItemStack[items.length];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
Object internal = items[i].getInternal();
|
||||
if (internal != null && internal instanceof ItemStack) {
|
||||
output[i] = (ItemStack) internal;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
public static ItemStack[] getItemStacks(List<IItemStack> items) {
|
||||
ItemStack[] output = new ItemStack[items.size()];
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
Object internal = items.get(i).getInternal();
|
||||
if (internal != null && internal instanceof ItemStack) {
|
||||
output[i] = (ItemStack) internal;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
public static IItemStack[] getIItemStacks(ItemStack... items) {
|
||||
IItemStack[] result = new IItemStack[items.length];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
result[i] = new MCItemStack(items[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static IItemStack[] getIItemStacks(List<ItemStack> items) {
|
||||
IItemStack[] result = new IItemStack[items.size()];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = new MCItemStack(items.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
[
|
||||
{
|
||||
"modid": "MineTweaker3",
|
||||
"name": "MineTweaker 3",
|
||||
"version": "${version}",
|
||||
"mcversion": "${mcversion}",
|
||||
"description": "Customize your minecraft experience!",
|
||||
"url": "http://minetweaker3.powerofbytes.com/wiki/",
|
||||
"credits": "Stan Hebben",
|
||||
"authors": [ "Stan Hebben" ],
|
||||
}
|
||||
]
|
||||
@@ -19,7 +19,7 @@ buildscript {
|
||||
|
||||
apply plugin: 'forge'
|
||||
minecraft{version = "1.7.2-10.12.2.1121"}
|
||||
version = "1.0"
|
||||
version = "1.7.2-3.0.0"
|
||||
archivesBaseName = project.projectDir.name
|
||||
|
||||
dependencies {
|
||||
@@ -36,3 +36,19 @@ task makeRegistry(type: RegisterZenClassesTask) {
|
||||
}
|
||||
|
||||
tasks.jar.dependsOn(makeRegistry)
|
||||
|
||||
processResources
|
||||
{
|
||||
// replace stuff in mcmod.info, nothing else
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include 'mcmod.info'
|
||||
|
||||
// replace version and mcversion
|
||||
expand 'version':project.version, 'mcversion':project.minecraft.version
|
||||
}
|
||||
|
||||
// copy everything else, thats not the mcmod.info
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
exclude 'mcmod.info'
|
||||
}
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
+14
-29
@@ -73,30 +73,6 @@ public class MineTweakerCommand implements ICommand {
|
||||
" Outputs all active mod IDs in the game",
|
||||
"minetweaker name <id>",
|
||||
" Outputs the name for the given item ID"
|
||||
/* "minetweaker name <id>[:<meta>]",
|
||||
" Prints the unlocalized name of the specified item," +
|
||||
" can be used as item or block name",
|
||||
"minetweaker liquid <id>[:<meta>]",
|
||||
" Prints the unlocalized liquid name in the specified container," +
|
||||
" con be used as liquid name",
|
||||
"minetweaker oredict",
|
||||
" Prints a list of all ore dictionary entries",
|
||||
"minetweaker oredict <id>[:<meta>]",
|
||||
" Prints the ore dictionary name(s) for the specified item",
|
||||
"minetweaker oredict <name>",
|
||||
" Prints all items for the specified ore dictionary name",
|
||||
"minetweaker recipes <id>[:<meta>]",
|
||||
" Prints all recipes for the specified item",
|
||||
"minetweaker fuel <id>[:<meta>]",
|
||||
" Retrieves the fuel value for the specified item",
|
||||
"minetweaker reload",
|
||||
" Reloads the server-side script (experimental)",
|
||||
"minetweaker logdamage=on",
|
||||
" Enables damage logging",
|
||||
"minetweaker logdamage=off",
|
||||
" Disables damage logging",
|
||||
"minetweaker reload",
|
||||
" Reloads the server script"*/
|
||||
}, "\n");
|
||||
}
|
||||
|
||||
@@ -223,11 +199,20 @@ public class MineTweakerCommand implements ICommand {
|
||||
MineTweakerAPI.logger.logCommand("Mod: " + mod.getModId());
|
||||
}
|
||||
} else if (arguments[0].equals("name")) {
|
||||
try {
|
||||
int id = Integer.parseInt(arguments[1]);
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
MineTweakerAPI.logger.logCommand("ID must be an integer");
|
||||
if (arguments.length < 2) {
|
||||
sendChatMessage(icommandsender, "missing id parameter");
|
||||
} else {
|
||||
try {
|
||||
int id = Integer.parseInt(arguments[1]);
|
||||
Item item = Item.getItemById(id);
|
||||
StringBuilder description = new StringBuilder();
|
||||
description.append('<');
|
||||
description.append(Item.itemRegistry.getNameForObject(item));
|
||||
description.append('>');
|
||||
sendChatMessage(icommandsender, description.toString());
|
||||
} catch (NumberFormatException e) {
|
||||
MineTweakerAPI.logger.logCommand("ID must be an integer");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loaded 100 of 126 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user